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