In the absence of proper validation, at least check that null bytes
do not appear as anything but the first byte of a multibyte character.
This commit is contained in:
parent
bbf15239ed
commit
88af941a73
@ -122,6 +122,10 @@ _BIG5_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n,
|
||||
if (n == 0 || (size_t)(len = _big5_check(*s)) > n)
|
||||
/* Incomplete multibyte sequence */
|
||||
return ((size_t)-2);
|
||||
if (n == 2 && s[1] == '\0') {
|
||||
errno = EILSEQ;
|
||||
return ((size_t)-1);
|
||||
}
|
||||
wc = 0;
|
||||
i = len;
|
||||
while (i-- > 0)
|
||||
|
@ -185,8 +185,14 @@ _EUC_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n,
|
||||
/* FALLTHROUGH */
|
||||
case 1:
|
||||
case 0:
|
||||
while (remain-- > 0)
|
||||
wc = (unsigned char)*s++;
|
||||
while (--remain > 0) {
|
||||
if (*s == '\0') {
|
||||
errno = EILSEQ;
|
||||
return ((size_t)-1);
|
||||
}
|
||||
wc = (wc << 8) | (unsigned char)*s++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
wc = (wc & ~CEI->mask) | CEI->bits[set];
|
||||
|
@ -119,6 +119,10 @@ _GBK_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n,
|
||||
if (n == 0 || (size_t)(len = _gbk_check(*s)) > n)
|
||||
/* Incomplete multibyte sequence */
|
||||
return ((size_t)-2);
|
||||
if (n == 2 && s[1] == '\0') {
|
||||
errno = EILSEQ;
|
||||
return ((size_t)-1);
|
||||
}
|
||||
wc = 0;
|
||||
i = len;
|
||||
while (i-- > 0)
|
||||
|
@ -118,6 +118,10 @@ _MSKanji_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n,
|
||||
if (n < 2)
|
||||
/* Incomplete multibyte sequence */
|
||||
return ((size_t)-2);
|
||||
if (*s == '\0') {
|
||||
errno = EILSEQ;
|
||||
return ((size_t)-1);
|
||||
}
|
||||
wc = (wc << 8) | (*s++ & 0xff);
|
||||
len = 2;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user