printf should not SEGV when passed NULL for %s format

Author: Darren Moffat 
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.

Comments:

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 03:26 PM BST #

Wow, that's great! Thanks.

Posted by Guest on June 24, 2009 at 05:01 PM 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 03: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 09:48 AM 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 10:00 AM 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 02:45 AM BST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

DarrenMoffat

Search

Categories
Archives
« April 2014
MonTueWedThuFriSatSun
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    
       
Today