Commit b47ed0a2 authored by Geoff Simmons's avatar Geoff Simmons

fix base64_decode() for BASE64URLNOPAD

parent 9d6513e6
......@@ -189,14 +189,14 @@ base64_decode(const enum encoding dec, char *restrict const buf,
const size_t maxlen, const char *restrict const p, va_list ap)
{
struct b64_alphabet *alpha = &b64_alphabet[dec];
const char *s;
char *dest = buf;
unsigned u = 0, term = 0;
int n = 0;
AN(buf);
for (s = p; s != vrt_magic_string_end; s = va_arg(ap, const char *)) {
for (const char *s = p; s != vrt_magic_string_end;
s = va_arg(ap, const char *)) {
if (s == NULL)
continue;
if (*s && term) {
......@@ -229,11 +229,14 @@ base64_decode(const enum encoding dec, char *restrict const buf,
}
}
}
if (n)
if (n) {
if (!alpha->padding)
u <<= 6 * (4 - n);
if (decode(&dest, buf, maxlen, u, n-term) < 0) {
errno = ENOMEM;
return -1;
}
}
return dest - buf;
}
......@@ -68,6 +68,25 @@ varnish v1 -vcl+backend {
+ "H" + resp.http.mid2 + "kLw"
+ resp.http.pad));
set resp.http.decnopad = convert.encode(IDENTITY,
convert.decode(BASE64URLNOPAD,
"L0hlbGxvIHdvcmxkLw"));
set resp.http.decnopad2pieces
= convert.encode(IDENTITY, convert.decode(BASE64URLNOPAD,
resp.http.l + "0hlbGxvIHdvcmxkLw"));
set resp.http.decnopad6pieces
= convert.encode(IDENTITY, convert.decode(BASE64URLNOPAD,
resp.http.l + "0hlb" + resp.http.mid1
+ "H" + resp.http.mid2 + "kLw"));
set resp.http.decnopadlong
= convert.encode(IDENTITY,
convert.decode(BASE64URLNOPAD,
"VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw"
));
}
} -start
......@@ -86,6 +105,10 @@ client c1 {
expect resp.http.dec2pieces == "/Hello world/"
expect resp.http.dec3pieces == "/Hello world/"
expect resp.http.dec7pieces == "/Hello world/"
expect resp.http.decnopad == "/Hello world/"
expect resp.http.decnopad2pieces == "/Hello world/"
expect resp.http.decnopad6pieces == "/Hello world/"
expect resp.http.decnopadlong == "The quick brown fox jumps over the lazy dog"
}
client c1 -run
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