From 7de17d91bb025783c4d6e516f2d59a27e9f514ea Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 16 Mar 2017 16:24:12 +0000 Subject: [PATCH] [CritFix] Fix base64 decoding when there are unparseable characters --- src/libcryptobox/base64/ref.c | 13 +++++++++++-- src/libcryptobox/base64/sse42.c | 13 +++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/libcryptobox/base64/ref.c b/src/libcryptobox/base64/ref.c index 13e3b1040..2d757fe23 100644 --- a/src/libcryptobox/base64/ref.c +++ b/src/libcryptobox/base64/ref.c @@ -174,6 +174,9 @@ repeat: break; } } + else { + leftover --; + } /* If we get here, there was an error: */ break; } @@ -188,12 +191,18 @@ repeat: break; } if ((q = base64_table_dec[*c++]) >= 254) { - leftover = 0; /* * When q == 254, the input char is '='. Return 1 and EOF. * When q == 255, the input char is invalid. Return 0 and EOF. */ - ret = ((q == 254) && (inlen == 0)) ? 1 : 0; + if (q == 254 && inlen == 0) { + ret = 1; + leftover = 0; + } + else { + ret = 0; + } + break; } diff --git a/src/libcryptobox/base64/sse42.c b/src/libcryptobox/base64/sse42.c index ea5a6e1d6..12c6e3413 100644 --- a/src/libcryptobox/base64/sse42.c +++ b/src/libcryptobox/base64/sse42.c @@ -203,6 +203,9 @@ repeat: break; } } + else { + leftover --; + } /* If we get here, there was an error: */ break; } @@ -217,12 +220,18 @@ repeat: break; } if ((q = base64_table_dec[*c++]) >= 254) { - leftover = 0; /* * When q == 254, the input char is '='. Return 1 and EOF. * When q == 255, the input char is invalid. Return 0 and EOF. */ - ret = ((q == 254) && (inlen == 0)) ? 1 : 0; + if (q == 254 && inlen == 0) { + ret = 1; + leftover = 0; + } + else { + ret = 0; + } + break; } -- 2.39.5