From: Vsevolod Stakhov Date: Tue, 13 Dec 2016 17:39:51 +0000 (+0000) Subject: [Feature] Ignore bad symbols on base64 decoding X-Git-Tag: 1.5.0~592 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2d6db9acb0e06c61f034407b64dcc41280a7b8c9;p=thirdparty%2Frspamd.git [Feature] Ignore bad symbols on base64 decoding --- diff --git a/src/libcryptobox/base64/ref.c b/src/libcryptobox/base64/ref.c index 22cedee6a9..13e3b1040d 100644 --- a/src/libcryptobox/base64/ref.c +++ b/src/libcryptobox/base64/ref.c @@ -119,6 +119,7 @@ base64_decode_ref (const char *in, size_t inlen, size_t outl = 0; size_t leftover = 0; +repeat: switch (leftover) { for (;;) { case 0: @@ -133,7 +134,7 @@ base64_decode_ref (const char *in, size_t inlen, break; } if ((q = base64_table_dec[*c++]) >= 254) { - + ret = 0; break; } carry = q << 2; @@ -145,7 +146,8 @@ base64_decode_ref (const char *in, size_t inlen, break; } if ((q = base64_table_dec[*c++]) >= 254) { - return (-1); + ret = 0; + break; } *o++ = carry | (q >> 4); carry = q << 4; @@ -202,6 +204,18 @@ base64_decode_ref (const char *in, size_t inlen, } } + if (!ret && inlen > 0) { + /* Skip to the next valid character in input */ + while (base64_table_dec[*c] >= 254 && inlen > 0) { + c ++; + inlen --; + } + + if (inlen > 0) { + goto repeat; + } + } + *outlen = outl; return ret;