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
parent a390e080
......@@ -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
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment