From 781c6f3227ec1009a3d313f33764f03796b49b42 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Sun, 9 Jan 2022 12:46:27 +0000 Subject: [PATCH] base64: prevent writing null char into zero length output buffer This allows handling of the unusal but foreseeable situation were the client provides a zero length output buffer, for example, if the input buffer was also zero length. --- lib/misc/base64-decode.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/misc/base64-decode.c b/lib/misc/base64-decode.c index 9d18b33fc..0776509f7 100644 --- a/lib/misc/base64-decode.c +++ b/lib/misc/base64-decode.c @@ -164,7 +164,9 @@ lws_b64_decode_stateful(struct lws_b64state *s, const char *in, size_t *in_len, s->len = 0; } - *out = '\0'; + if (out < end_out) + *out = '\0'; + *in_len = (unsigned int)(in - orig_in); *out_size = (unsigned int)(out - orig_out);