From 04acf365090abb30242e8fc54de285c9d8b29eb4 Mon Sep 17 00:00:00 2001 From: David Schultz Date: Sat, 21 Apr 2012 06:08:29 +0000 Subject: [PATCH] Ensure that the {,v}swprintf functions always null-terminate the output string, even if an encoding error or malloc failure occurs. --- lib/libc/stdio/vswprintf.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/libc/stdio/vswprintf.c b/lib/libc/stdio/vswprintf.c index 023c53750f2..4b1e382fd44 100644 --- a/lib/libc/stdio/vswprintf.c +++ b/lib/libc/stdio/vswprintf.c @@ -66,6 +66,7 @@ vswprintf_l(wchar_t * __restrict s, size_t n, locale_t locale, 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 */ @@ -74,6 +75,7 @@ vswprintf_l(wchar_t * __restrict s, size_t n, locale_t locale, sverrno = errno; free(f._bf._base); errno = sverrno; + *s = L'\0'; return (-1); } *f._p = '\0'; @@ -87,6 +89,7 @@ vswprintf_l(wchar_t * __restrict s, size_t n, locale_t locale, free(f._bf._base); if (nwc == (size_t)-1) { errno = EILSEQ; + *s = L'\0'; return (-1); } if (nwc == n) { -- 2.45.0