Skip to content
Permalink
Browse files

PSARC/2008/403 libc printf behaviour for NULL string

6724478 libc printf should not SEGV when passed NULL for %s format
  • Loading branch information...
Darren Moffat Darren Moffat
Darren Moffat authored and Darren Moffat committed Jun 24, 2009
1 parent 8eb14f4 commit 9f773e288f99c442ca8578e3006a51f82fb49aab
Showing with 12 additions and 1 deletion.
  1. +12 −1 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 @@ _ndoprnt(const char *format, va_list in_args, FILE *iop, int prflag)
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 @@ _ndoprnt(const char *format, va_list in_args, FILE *iop, int prflag)
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 @@ _ndoprnt(const char *format, va_list in_args, FILE *iop, int prflag)
}
#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 @@ _ndoprnt(const char *format, va_list in_args, FILE *iop, int prflag)
wflag = 1;
#else /* _WIDE */
bp = va_arg(args.ap, char *);
if (bp == NULL)
bp = (char *)nullstr;
if (!(flagword & DOTSEEN)) {
if (wflag) {
/* wide character handling */

0 comments on commit 9f773e2

Please sign in to comment.
You can’t perform that action at this time.