This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[review v2] wcsrtombs: Do not call wcsnlen on input with wrong length [BZ #23711]
- From: "Carlos O'Donell (Code Review)" <gerrit at gnutoolchain-gerrit dot osci dot io>
- To: Florian Weimer <fweimer at redhat dot com>, libc-alpha at sourceware dot org
- Date: Wed, 27 Nov 2019 14:12:38 -0500
- Subject: [review v2] wcsrtombs: Do not call wcsnlen on input with wrong length [BZ #23711]
- Auto-submitted: auto-generated
- References: <gerrit.1572431418000.I5b28fb36c8d224cf69910fb436ff76bff8f129f6@gnutoolchain-gerrit.osci.io>
- Reply-to: gnutoolchain-gerrit at osci dot io
Carlos O'Donell has posted comments on this change.
Change URL: https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/445
......................................................................
Patch Set 2: Code-Review+2
(1 comment)
OK for master.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
| --- wcsmbs/wcsrtombs.c
| +++ wcsmbs/wcsrtombs.c
| @@ -98,17 +98,29 @@ #endif
| }
| else
| {
| - /* This code is based on the safe assumption that all internal
| - multi-byte encodings use the NUL byte only to mark the end
| - of the string. */
| - const wchar_t *srcend = *src + __wcsnlen (*src, len) + 1;
| size_t dummy;
|
| + /* This code is based on the safe assumption that all internal
| + multi-byte encodings use the NUL byte only to mark the end of
| + the string. It also assumes that every wide character
| + produces at least one byte of output. This is true for all
| + supported locales, including the very special case of the
| + Big5 character set. But custom locales (e.g., for TSCII)
| + might not have this property.
| +
| + Do not use wcsnlen because the input may not be an array of
| + len wchar_t elements, given that len is the length of the
| + *destination* array. */
| + const wchar_t *srcend = *src;
| + while (srcend < *src + len && *srcend != L'\0')
| + ++srcend;
| + ++srcend;
PS2, Line 117:
OK. This looks good to me. We scan src looking for L'\0' rather than
using wcsnlen which is undefined because len may be longer than src's
real length.
| +
| data.__outbuf = (unsigned char *) dst;
| data.__outbufend = (unsigned char *) dst + len;
|
| status = DL_CALL_FCT (fct, (tomb, &data, (const unsigned char **) src,
| (const unsigned char *) srcend, NULL,
| &dummy, 0, 1));
|
| /* Count the number of bytes. */
--
Gerrit-Project: glibc
Gerrit-Branch: master
Gerrit-Change-Id: I5b28fb36c8d224cf69910fb436ff76bff8f129f6
Gerrit-Change-Number: 445
Gerrit-PatchSet: 2
Gerrit-Owner: Florian Weimer <fweimer@redhat.com>
Gerrit-Reviewer: Carlos O'Donell <carlos@redhat.com>
Gerrit-Reviewer: Florian Weimer <fweimer@redhat.com>
Gerrit-Comment-Date: Wed, 27 Nov 2019 19:12:38 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment