LWN.net Logo

In 2011?

In 2011?

Posted Feb 2, 2012 22:11 UTC (Thu) by iabervon (subscriber, #722)
In reply to: In 2011? by NAR
Parent article: Format string vulnerabilities

Nobody does write printf(variable). Unfortunately, they do write vprintf(fmt, args), where fmt is the concatenation of some strings and an appropriate format string. The goals were: call a single stdio function in order to avoid interleaving your message with other output (potentially from a subprocess); print a bit of identifying information at the beginning; and print a caller-supplied format string with its appropriate arguments. There's not really a good way to do all of these together, since you can't insert things in a va_list.


(Log in to post comments)

In 2011?

Posted Feb 8, 2012 3:11 UTC (Wed) by IkeTo (subscriber, #2122) [Link]

Format string with character not controlled by the application is universally bad. I think it is more reasonable to vsnprintf the application-supplied information to a fixed sized buffer, and printf the result with the user-supplied argv[0] with a fixed fmt. This limits the length of the output to the buffer size, but that is probably good for a log file anyway. The double-copy speed overhead is probably irrelevant.

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds