libc/base64: check buffer overflow for last char

Signed-off-by: Xu Xingliang <xuxingliang@xiaomi.com>
This commit is contained in:
Xu Xingliang 2024-04-12 22:12:12 +08:00 committed by Xiang Xiao
parent 4ed506d6ab
commit b75412d96a

View file

@ -83,7 +83,12 @@ int b64_ntop(FAR const unsigned char *src, size_t srclen,
*target++ = g_pad64;
}
*target = '\0';
if (datalen >= targsize)
{
return -1;
}
*target = '\0'; /* Returned length doesn't include '\0' */
return datalen;
}