Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 24 Apr 2012 03:59:18 +0000 (UTC)
From:      David Schultz <das@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org
Subject:   svn commit: r234634 - stable/8/lib/libc/stdio
Message-ID:  <201204240359.q3O3xIlk029388@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: das
Date: Tue Apr 24 03:59:18 2012
New Revision: 234634
URL: http://svn.freebsd.org/changeset/base/234634

Log:
  MFC r234529:
    Ensure that the {,v}swprintf functions always null-terminate the
    output string, even if an encoding error or malloc failure occurs.

Modified:
  stable/8/lib/libc/stdio/vswprintf.c
Directory Properties:
  stable/8/lib/libc/   (props changed)

Modified: stable/8/lib/libc/stdio/vswprintf.c
==============================================================================
--- stable/8/lib/libc/stdio/vswprintf.c	Tue Apr 24 03:59:13 2012	(r234633)
+++ stable/8/lib/libc/stdio/vswprintf.c	Tue Apr 24 03:59:18 2012	(r234634)
@@ -59,6 +59,7 @@ vswprintf(wchar_t * __restrict s, size_t
 	f._bf._base = f._p = (unsigned char *)malloc(128);
 	if (f._bf._base == NULL) {
 		errno = ENOMEM;
+		*s = L'\0';
 		return (-1);
 	}
 	f._bf._size = f._w = 127;		/* Leave room for the NUL */
@@ -67,6 +68,7 @@ vswprintf(wchar_t * __restrict s, size_t
 		sverrno = errno;
 		free(f._bf._base);
 		errno = sverrno;
+		*s = L'\0';
 		return (-1);
 	}
 	*f._p = '\0';
@@ -80,6 +82,7 @@ vswprintf(wchar_t * __restrict s, size_t
 	free(f._bf._base);
 	if (nwc == (size_t)-1) {
 		errno = EILSEQ;
+		*s = L'\0';
 		return (-1);
 	}
 	if (nwc == n) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201204240359.q3O3xIlk029388>