fix(core): Avoid buffer overflow in base64 decoding (length check)

This commit is contained in:
Stefan Profanter 2019-11-07 12:31:51 +01:00 committed by Stefan Profanter
parent 17776739a3
commit 95b3deb6a1

10
deps/base64.c vendored
View File

@ -92,9 +92,19 @@ UA_unbase64(const unsigned char *src, size_t len, size_t *out_len) {
}
if(pad1) {
if (last + 1 >= len) {
UA_free(str);
*out_len = 0;
return (unsigned char*)UA_EMPTY_ARRAY_SENTINEL;
}
uint32_t n = from_b64[p[last]] << 18 | from_b64[p[last + 1]] << 12;
*pos++ = (unsigned char)(n >> 16);
if(pad2) {
if (last + 2 >= len) {
UA_free(str);
*out_len = 0;
return (unsigned char*)UA_EMPTY_ARRAY_SENTINEL;
}
n |= from_b64[p[last + 2]] << 6;
*pos++ = (unsigned char)(n >> 8 & 0xFF);
}