Wednesday June 24, 2009 Author: Darren Moffat( Jun 24 2009, 06:14:05 PM BST ) Permalink Comments [6]Repository: /export/onnv-gate Total changesets: 1 Changeset: acbef346fd18 Comments: PSARC/2008/403 libc printf behaviour for NULL string 6724478 libc printf should not SEGV when passed NULL for %s format Files: modified: usr/src/lib/libc/port/print/doprnt.c
Finally got this in.
Does this change also garantee that there won't be a legit string at 0x0? (eg. by hiding the first page from the allocator, or mapping it, like 0@0.so does)
Posted by PG on June 24, 2009 at 10:26 PM BST #
Wow, that's great! Thanks.
Posted by Guest on June 25, 2009 at 12:01 AM BST #
PG this change only changes printf(3C) to the same printf(3C) behaviour as other platforms is don't SEGV is %s is given NULL. Nothing more nothing less (well it works for char * and wchar_t *).
Posted by Darren Moffat on June 25, 2009 at 10:22 AM BST #
How does one get the old behavior for those of us that want our applications to SEGV when we attempt to print NULL?
Posted by Shawn Walker on June 25, 2009 at 04:48 PM BST #
@Shawn: You don't, see the ARC case for why not - and remeber Solaris was the odd one out here and not even self consistent the kernel already panic when given NULL to a printf %s.
Posted by Darren Moffat on June 25, 2009 at 05:00 PM BST #
@Shawn: at source level, you could always
assert(s != NULL);
printf("%s is really boring\n", s);
If the behavior of printf with an NULL argument
for a %s is unspecified, that at least is correct
insofar as it does not depend on that behavior.
(although the philosophical point is probably
moot, if it has been wrong to depend on _not_
causing a core dump with this practice on other
platforms, it's just as wrong to depend on it
causing one here)
Posted by rlhamil on July 08, 2009 at 09:45 AM BST #