Commit e39f531c authored by Geoff Simmons's avatar Geoff Simmons

bugfix: in decode_n for base64, count down inlen before breaking when

we hit the null terminator for a string in a STRING_LIST
parent 1bd658d4
...@@ -60,12 +60,16 @@ decode(char *restrict *restrict dest, char *restrict const buf, ...@@ -60,12 +60,16 @@ decode(char *restrict *restrict dest, char *restrict const buf,
{ {
char *d; char *d;
if (n <= 1) if (n <= 1) {
errno = EINVAL;
return -1; return -1;
}
d = *dest; d = *dest;
for (int i = 0; i < n - 1; i++) { for (int i = 0; i < n - 1; i++) {
if (d == buf + buflen) if (d == buf + buflen) {
errno = ENOMEM;
return -1; return -1;
}
*d++ = (u >> 16) & 0xff; *d++ = (u >> 16) & 0xff;
u <<= 8; u <<= 8;
} }
...@@ -154,19 +158,17 @@ base64_decode(const enum encoding dec, char *restrict const buf, ...@@ -154,19 +158,17 @@ base64_decode(const enum encoding dec, char *restrict const buf,
continue; continue;
} }
u |= (unsigned) b; u |= (unsigned) b;
if (!*s)
break;
if (inlen != -1) { if (inlen != -1) {
--inlen; --inlen;
if (inlen == 0) if (inlen == 0)
break; break;
} }
if (!*s)
break;
} }
if (n == 4) { if (n == 4) {
if (decode(&dest, buf, buflen, u, n-term) < 0) { if (decode(&dest, buf, buflen, u, n-term) < 0)
errno = ENOMEM;
return -1; return -1;
}
n = 0; n = 0;
} }
} }
...@@ -176,10 +178,8 @@ base64_decode(const enum encoding dec, char *restrict const buf, ...@@ -176,10 +178,8 @@ base64_decode(const enum encoding dec, char *restrict const buf,
if (n) { if (n) {
if (!alpha->padding) if (!alpha->padding)
u <<= 6 * (4 - n); u <<= 6 * (4 - n);
if (decode(&dest, buf, buflen, u, n-term) < 0) { if (decode(&dest, buf, buflen, u, n-term) < 0)
errno = ENOMEM;
return -1; return -1;
}
} }
return dest - buf; return dest - buf;
......
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