diff options
author | das <das@FreeBSD.org> | 2012-04-21 06:08:29 +0000 |
---|---|---|
committer | das <das@FreeBSD.org> | 2012-04-21 06:08:29 +0000 |
commit | 8595324df362b03e7f89d001d9ba51dddcc6a02e (patch) | |
tree | f865b8f783a82fea251acddcc02c62aee707b187 /lib/libc/stdio/vswprintf.c | |
parent | 9da846a0f4d303010f8d4dd8526462ec0effe76e (diff) | |
download | FreeBSD-src-8595324df362b03e7f89d001d9ba51dddcc6a02e.zip FreeBSD-src-8595324df362b03e7f89d001d9ba51dddcc6a02e.tar.gz |
Ensure that the {,v}swprintf functions always null-terminate the
output string, even if an encoding error or malloc failure occurs.
Diffstat (limited to 'lib/libc/stdio/vswprintf.c')
-rw-r--r-- | lib/libc/stdio/vswprintf.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/lib/libc/stdio/vswprintf.c b/lib/libc/stdio/vswprintf.c index 023c537..4b1e382 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) { |