[6.0] 2de3203d0 Fix base64 decoding for length= argument and non-padding decoding
    Dridi Boukelmoune 
    dridi.boukelmoune at gmail.com
       
    Fri Nov 19 10:06:10 UTC 2021
    
    
  
commit 2de3203d0b3f133637e834ebb03ee462c3d84212
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 6e6004f63..34bf497c5 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 20a4ac877..1dea4c5e3 100644
--- a/lib/libvmod_blob/base64.c
+++ b/lib/libvmod_blob/base64.c
@@ -185,7 +185,7 @@ base64_decode(const enum encoding dec, char *restrict const 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