diff options
author | Darren Moffat <Darren.Moffat@Sun.COM> | 2009-06-24 15:30:04 +0100 |
---|---|---|
committer | Darren Moffat <Darren.Moffat@Sun.COM> | 2009-06-24 15:30:04 +0100 |
commit | 9f773e288f99c442ca8578e3006a51f82fb49aab (patch) | |
tree | 24f19eecc588d2c673b298a6f0cdd2b20c434cc4 /usr/src/lib/libc | |
parent | 8eb14f4097833f28f2a675c442e3f0188b814452 (diff) | |
download | illumos-joyent-9f773e288f99c442ca8578e3006a51f82fb49aab.tar.gz |
PSARC/2008/403 libc printf behaviour for NULL string
6724478 libc printf should not SEGV when passed NULL for %s format
Diffstat (limited to 'usr/src/lib/libc')
-rw-r--r-- | usr/src/lib/libc/port/print/doprnt.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/usr/src/lib/libc/port/print/doprnt.c b/usr/src/lib/libc/port/print/doprnt.c index 2ad59ab3e5..c291970f8e 100644 --- a/usr/src/lib/libc/port/print/doprnt.c +++ b/usr/src/lib/libc/port/print/doprnt.c @@ -20,7 +20,7 @@ */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -52,6 +52,9 @@ #include "mse.h" #include "xpg6.h" +static const char nullstr[] = "(null)"; +static const wchar_t widenullstr[] = L"(null)"; + #if defined(__i386) || defined(__amd64) || defined(__sparcv9) #define GETQVAL(arg) (va_arg(arg, long double)) #else /* !defined(__i386) && !defined(__sparcv9) */ @@ -1748,6 +1751,8 @@ wide_S: lflag++; } bp = va_arg(args.ap, wchar_t *); + if (bp == NULL) + bp = (wchar_t *)widenullstr; if (!(flagword & DOTSEEN)) { /* wide character handling */ prec = MAXINT; @@ -1770,6 +1775,8 @@ wide_S: if (!wflag) wflag++; bp = va_arg(args.ap, char *); + if (bp == NULL) + bp = (char *)widenullstr; if (!(flagword & DOTSEEN)) { /* wide character handling */ prec = MAXINT; @@ -1802,6 +1809,8 @@ wide_S: } #ifdef _WIDE cbp = va_arg(args.ap, char *); + if (cbp == NULL) + cbp = (char *)nullstr; if (!(flagword & DOTSEEN)) { size_t nwc; wchar_t *wstr; @@ -1863,6 +1872,8 @@ wide_S: wflag = 1; #else /* _WIDE */ bp = va_arg(args.ap, char *); + if (bp == NULL) + bp = (char *)nullstr; if (!(flagword & DOTSEEN)) { if (wflag) { /* wide character handling */ |