From 6b936fb2c14e49cbae178a232606be76a6c0416f Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Mon, 29 Apr 2019 14:57:29 +0100 Subject: [PATCH] libmutt: fix base64 code for degenerate cases --- mutt/base64.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mutt/base64.c b/mutt/base64.c index c67613d63..728e58893 100644 --- a/mutt/base64.c +++ b/mutt/base64.c @@ -87,6 +87,9 @@ const int Index64[128] = { */ size_t mutt_b64_encode(const char *in, size_t inlen, char *out, size_t outlen) { + if (!in || !out) + return 0; + unsigned char *begin = (unsigned char *) out; const unsigned char *inu = (const unsigned char *) in; @@ -132,6 +135,9 @@ size_t mutt_b64_encode(const char *in, size_t inlen, char *out, size_t outlen) */ int mutt_b64_decode(const char *in, char *out, size_t olen) { + if (!in || !out) + return -1; + int len = 0; unsigned char digit4; @@ -184,6 +190,9 @@ int mutt_b64_decode(const char *in, char *out, size_t olen) */ size_t mutt_b64_buffer_encode(struct Buffer *buf, const char *in, size_t len) { + if (!buf) + return 0; + mutt_buffer_increase_size(buf, MAX((len * 2), 1024)); size_t num = mutt_b64_encode(in, len, buf->data, buf->dsize); mutt_buffer_fix_dptr(buf); @@ -199,6 +208,9 @@ size_t mutt_b64_buffer_encode(struct Buffer *buf, const char *in, size_t len) */ int mutt_b64_buffer_decode(struct Buffer *buf, const char *in) { + if (!buf) + return -1; + mutt_buffer_increase_size(buf, mutt_str_strlen(in)); int olen = mutt_b64_decode(in, buf->data, buf->dsize); /* mutt_from_base64 returns raw bytes, so don't terminate the buffer either */ -- 2.40.0