diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-12-13 17:39:51 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-12-13 17:39:51 +0000 |
commit | 2d6db9acb0e06c61f034407b64dcc41280a7b8c9 (patch) | |
tree | 44e6e447f033c4bd86ed1b8917b6d3eade15d924 /src/libcryptobox | |
parent | 58e9918083df89592a4321328ba944ef835861d1 (diff) | |
download | rspamd-2d6db9acb0e06c61f034407b64dcc41280a7b8c9.tar.gz rspamd-2d6db9acb0e06c61f034407b64dcc41280a7b8c9.zip |
[Feature] Ignore bad symbols on base64 decoding
Diffstat (limited to 'src/libcryptobox')
-rw-r--r-- | src/libcryptobox/base64/ref.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/libcryptobox/base64/ref.c b/src/libcryptobox/base64/ref.c index 22cedee6a..13e3b1040 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; |