lib_iconv.c:Fix possible out-of-bounds reads

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
This commit is contained in:
chenrun1 2023-09-14 15:46:28 +08:00 committed by Xiang Xiao
parent c9bc6b1ad5
commit 4ce205cf08

View File

@ -420,6 +420,20 @@ size_t iconv(iconv_t cd, FAR char **in, FAR size_t *inb,
to = extract_to(cd);
from = extract_from(cd);
if (to > sizeof(g_charmaps) - 1)
{
/* Avoid going outside the range of the array */
to = sizeof(g_charmaps) - 1;
}
if (from > sizeof(g_charmaps) - 1)
{
/* Avoid going outside the range of the array */
from = sizeof(g_charmaps) - 1;
}
map = g_charmaps + from + 1;
tomap = g_charmaps + to + 1;
type = map[0 - 1];