Skip to content

Commit

Permalink
lws_b64_decode_stateful truncates response
Browse files Browse the repository at this point in the history
Addresses issue warmcat#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.
  • Loading branch information
darhaywa authored Mar 23, 2023
1 parent e8eb7d6 commit 70d41ec
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/misc/base64-decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ lws_b64_decode_stateful(struct lws_b64state *s, const char *in, size_t *in_len,
uint8_t *orig_out = out, *end_out = out + *out_size;
int equals = 0;

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;
Expand Down

0 comments on commit 70d41ec

Please sign in to comment.