News, tips, partners, and perspectives for the Oracle Solaris operating system

printf should not SEGV when passed NULL for %s format

Darren Moffat
Senior Software Architect
Author: Darren Moffat 
Repository: /export/onnv-gate
Total changesets: 1
Changeset: acbef346fd18
PSARC/2008/403 libc printf behaviour for NULL string
6724478 libc printf should not SEGV when passed NULL for %s format


Finally got this in.

Join the discussion

Comments ( 6 )
  • PG Wednesday, June 24, 2009

    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)

  • Guest Wednesday, June 24, 2009

    Wow, that's great! Thanks.

  • Darren Moffat Thursday, June 25, 2009

    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 \*).

  • Shawn Walker Thursday, June 25, 2009

    How does one get the old behavior for those of us that want our applications to SEGV when we attempt to print NULL?

  • Darren Moffat Thursday, June 25, 2009

    @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.

  • rlhamil Wednesday, July 8, 2009

    @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)

Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.