Re:Try Objective-C
by coldtea on Thursday May 09, 2013 @08:39PM
(#5683845)
Huh? How so?
[ Parent
| on HN ]
If the variable's value contains any format args, e.g. %s, then NSLog (or printf, or whatever string formatting function you're using) will look for another argument, which you didn't actually pass, so it starts looking at garbage stack values.
Besides causing incorrect output, this may crash your program, or potentially be a vector for an exploit.
Re:Try Objective-C
by joshschreuder on Thursday May 09, 2013 @11:57PM
(#5684528)
Is there any reason NSLog doesn't filter input to escape these format args?
It can't. http://en.wikipedia.org/wiki/Uncontrolled_format_string:
"In particular, the varargs mechanism allows functions to accept any number of arguments (e.g. printf) by "popping" as many arguments off the call stack as they wish, trusting the early arguments to indicate how many additional arguments are to be popped, and of what types."
NSLog is similar; it has to trust its first argument to be consistent with the number and types of arguments actually passed to it.
If you call NSLog(x), but do not have complete control over the value of x, you cannot guarantee that.
Because it's the format string, which the programmer is supposed to control?
NSLog(untrusted); bad. NSLog("The user entered %s", untrusted); OK.
Because that would defeat the entire purpose of NSLog.
Re:Try Objective-C
by jcromartie on Thursday May 09, 2013 @08:53PM
(#5683901)