1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

b64: lws_b64_decode_stateful truncates response

Addresses issue #2855 by allowing the parsing of the final byte when there are at least 3 bytes remaining in the buffer.

For every 4 bytes of input, a maximum of 3 bytes of output are generated when decoding the base64 string. The buffer space, therefore, only requires an additional 3 bytes of space. The code checks for space in the buffer before adding null termination.
This commit is contained in:
Daren Hayward 2023-03-23 15:36:02 +00:00 committed by Andy Green
parent 08ee6f14de
commit ac9e3ba677

View file

@ -113,7 +113,7 @@ lws_b64_decode_stateful(struct lws_b64state *s, const char *in, size_t *in_len,
const char *orig_in = in, *end_in = in + *in_len;
uint8_t *orig_out = out, *end_out = out + *out_size;
while (in < end_in && *in && out + 4 < end_out) {
while (in < end_in && *in && out + 3 <= end_out) {
for (; s->i < 4 && in < end_in && *in; s->i++) {
uint8_t v;