Commit 9d6513e6 authored by Geoff Simmons's avatar Geoff Simmons

bugfix base64_decode() for a concatenated STRING_LIST

parent 35bf67b2
......@@ -192,7 +192,7 @@ base64_decode(const enum encoding dec, char *restrict const buf,
const char *s;
char *dest = buf;
unsigned u = 0, term = 0;
int n;
int n = 0;
AN(buf);
......@@ -204,13 +204,14 @@ base64_decode(const enum encoding dec, char *restrict const buf,
return -1;
}
while (*s) {
for (n = 0; n < 4; n++) {
while (n < 4) {
char b = alpha->i64[(unsigned) *s++];
u <<= 6;
if (b == ILLEGAL) {
errno = EINVAL;
return -1;
}
n++;
if (b == PAD) {
term++;
continue;
......@@ -219,14 +220,16 @@ base64_decode(const enum encoding dec, char *restrict const buf,
if (!*s)
break;
}
if (n == 4)
if (n == 4) {
if (decode(&dest, buf, maxlen, u, n-term) < 0) {
errno = ENOMEM;
return -1;
}
n = 0;
}
}
}
if (n != 4)
if (n)
if (decode(&dest, buf, maxlen, u, n-term) < 0) {
errno = ENOMEM;
return -1;
......
......@@ -49,6 +49,25 @@ varnish v1 -vcl+backend {
= convert.encode(BASE64,
convert.decode(BASE64, "L0hlbGxvIHdvcmxkLw=="));
set resp.http.l = "L";
set resp.http.dec2pieces
= convert.encode(IDENTITY, convert.decode(BASE64,
resp.http.l + "0hlbGxvIHdvcmxkLw=="));
set resp.http.pad = "==";
set resp.http.dec3pieces
= convert.encode(IDENTITY, convert.decode(BASE64,
resp.http.l + "0hlbGxvIHdvcmxkLw"
+ resp.http.pad));
set resp.http.mid1 = "GxvI";
set resp.http.mid2 = "dvcmx";
set resp.http.dec7pieces
= convert.encode(IDENTITY, convert.decode(BASE64,
resp.http.l + "0hlb" + resp.http.mid1
+ "H" + resp.http.mid2 + "kLw"
+ resp.http.pad));
}
} -start
......@@ -64,6 +83,9 @@ client c1 {
expect resp.http.dec == "/Hello world/"
expect resp.http.dec2 == "The quick brown fox jumps over the lazy dog"
expect resp.http.decenc == "L0hlbGxvIHdvcmxkLw=="
expect resp.http.dec2pieces == "/Hello world/"
expect resp.http.dec3pieces == "/Hello world/"
expect resp.http.dec7pieces == "/Hello world/"
}
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