From 9aa2f5c5a21bfeceab16671fa2fc998f9ed1891b Mon Sep 17 00:00:00 2001 From: Aleksandr Vyhovanec Date: Fri, 19 Oct 2018 12:29:12 +0000 Subject: [PATCH] Merged in AVyhovanec/apps (pull request #158) "dst" overflow protection when base64 string ends with "=" Approved-by: GregoryN --- netutils/codecs/base64.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/netutils/codecs/base64.c b/netutils/codecs/base64.c index 780198955..05dab8775 100644 --- a/netutils/codecs/base64.c +++ b/netutils/codecs/base64.c @@ -290,24 +290,20 @@ static unsigned char *_base64_decode(const unsigned char *src, size_t len, if (count == 4) { *pos++ = (block[0] << 2) | (block[1] >> 4); + if (in[2] == ch) /* if (in[2] == '=') */ + { + break; + } *pos++ = (block[1] << 4) | (block[2] >> 2); + if (in[3] == ch) /* if (in[3] == '=') */ + { + break; + } *pos++ = (block[2] << 6) | block[3]; count = 0; } } - if (pos > out) - { - if (in[2] == ch) /* if (in[2] == '=') */ - { - pos -= 2; - } - else if (in[3] == ch) /* else if (in[3] == '=') */ - { - pos--; - } - } - *out_len = pos - out; return out; }