[master] fb044cb20 Fix base64 decoding for length= argument and non-padding decoding
Nils Goroll
nils.goroll at uplex.de
Thu Aug 6 15:16:08 UTC 2020
commit fb044cb204ca34493b2b33645938075ca64d2c73
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Thu Aug 6 17:10:33 2020 +0200
Fix base64 decoding for length= argument and non-padding decoding
When decoding only a substring, we naturally see no padding, so we must
not base tail processing on the number of pad characters seen, but
rather on the number of characters missing until the end of the current
block of four.
Fixes #3378
diff --git a/bin/varnishtest/tests/m00042.vtc b/bin/varnishtest/tests/m00042.vtc
index a03e46a3d..1f2db55b8 100644
--- a/bin/varnishtest/tests/m00042.vtc
+++ b/bin/varnishtest/tests/m00042.vtc
@@ -263,7 +263,7 @@ client c1 {
expect resp.http.hexmix2hexlc == resp.http.hexmix2hex
expect resp.http.hexparam == "0123456789"
expect resp.http.b642b64 == "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghij"
- expect resp.http.b64url2b64url == "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefeQ=="
+ expect resp.http.b64url2b64url == "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefgg=="
expect resp.http.b64urlnopad2b64urlnopad == "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefgg"
} -run
diff --git a/lib/libvmod_blob/base64.c b/lib/libvmod_blob/base64.c
index 06b4c1df0..909dc11e3 100644
--- a/lib/libvmod_blob/base64.c
+++ b/lib/libvmod_blob/base64.c
@@ -309,7 +309,7 @@ base64_decode(const enum encoding dec, blob_dest_t buf,
}
}
if (n) {
- if (!alpha->padding)
+ if (n - term != 0)
u <<= (6 * (4 - n));
if (decode(&dest, buf, buflen, u, n-term) < 0)
return (-1);
More information about the varnish-commit
mailing list