From 18b20312986af58ed39c318788680fabfad739f3 Mon Sep 17 00:00:00 2001 From: "Tim J. Robbins" Date: Tue, 25 May 2004 10:45:24 +0000 Subject: [PATCH] Scan the source string for invalid wide characters in wcsrtombs() in the dst == NULL case. --- lib/libc/locale/none.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/libc/locale/none.c b/lib/libc/locale/none.c index 6ac9a9e2712a..2a3ada6b3ee6 100644 --- a/lib/libc/locale/none.c +++ b/lib/libc/locale/none.c @@ -148,8 +148,15 @@ _none_wcsrtombs(char * __restrict dst, const wchar_t ** __restrict src, const wchar_t *s; size_t nchr; - if (dst == NULL) - return (wcslen(*src)); + if (dst == NULL) { + for (s = *src; *s != L'\0'; s++) { + if (*s < 0 || *s > UCHAR_MAX) { + errno = EILSEQ; + return ((size_t)-1); + } + } + return (s - *src); + } s = *src; nchr = 0;