]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: base64: dec func ignores padding for output size checking
authorEmeric Brun <ebrun@haproxy.com>
Mon, 14 Jan 2019 13:38:39 +0000 (14:38 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 14 Jan 2019 18:32:15 +0000 (19:32 +0100)
Decode function returns an error even if the ouptut buffer is
large enought because the padding was not considered. This
case was never met with current code base.

src/base64.c

index f7961c538cb3f8e65b21f7b90a8cba24178f6f8f..e7c9519200d93a0711ea52b8aba4bee543008593 100644 (file)
@@ -83,7 +83,9 @@ int base64dec(const char *in, size_t ilen, char *out, size_t olen) {
        if (ilen % 4)
                return -1;
 
-       if (olen < ilen / 4 * 3)
+       if (olen < ((ilen / 4 * 3)
+                   - (in[ilen-1] == '=' ? 1 : 0)
+                   - (in[ilen-2] == '=' ? 1 : 0)))
                return -2;
 
        while (ilen) {