Monday, December 12, 2011

Format string is not a string literal (potentially insecure)

I throw in a cheeky NSLog() to see where I've got to:

NSLog([myObject stringRepresentation]);

Hang on! A compiler warning:

Format string is not a string literal (potentially insecure)

What's this about?

A bit of Google (via this forum post) led me to a Wikipedia article on the Format string attack. It turns out that an attacker might use printf style format specifiers to do all sorts of nasty to my heap/stack.

The correct usage is this:

NSLog(@"%@", [myObject stringRepresentation]);

0 comments:

Post a Comment