Skip to content

Commit 00baa82

Browse files
committed
stdlib: Check for overlong UTF-8 encoding in mbtowc_r
UTF-8 starting with 0xc0 is invalid as any value like that could have been encoded in a single byte and Unicode does not allow for that. Signed-off-by: Keith Packard <[email protected]>
1 parent fe692dd commit 00baa82

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

newlib/libc/stdlib/mbtowc_r.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,10 @@ __utf8_mbtowc (
560560
}
561561
if (ch >= 0xc0 && ch <= 0xdf)
562562
{
563+
if (ch == 0xc0) {
564+
_REENT_ERRNO(r) = EILSEQ;
565+
return -1;
566+
}
563567
/* two-byte sequence */
564568
state->__value.__wchb[0] = ch;
565569
if (state->__count == 0)

0 commit comments

Comments
 (0)