Commit 0e0e007c authored by Geoff Simmons's avatar Geoff Simmons

only check for out of workspace in URL decode when it's necessary

parent 3d1dfa39
...@@ -133,16 +133,17 @@ url_decode(const enum encoding dec, char *restrict const buf, ...@@ -133,16 +133,17 @@ url_decode(const enum encoding dec, char *restrict const buf,
while (*s && len) { while (*s && len) {
uint8_t nib2; uint8_t nib2;
if (dest + 1 > end) {
errno = ENOMEM;
return -1;
}
switch(state) { switch(state) {
case NORMAL: case NORMAL:
if (*s == '%') if (*s == '%')
state = PERCENT; state = PERCENT;
else else {
if (dest == end) {
errno = ENOMEM;
return -1;
}
*dest++ = *s; *dest++ = *s;
}
break; break;
case PERCENT: case PERCENT:
if (isoutofrange(*s) if (isoutofrange(*s)
...@@ -153,6 +154,10 @@ url_decode(const enum encoding dec, char *restrict const buf, ...@@ -153,6 +154,10 @@ url_decode(const enum encoding dec, char *restrict const buf,
state = FIRSTNIB; state = FIRSTNIB;
break; break;
case FIRSTNIB: case FIRSTNIB:
if (dest == end) {
errno = ENOMEM;
return -1;
}
if (isoutofrange(*s) if (isoutofrange(*s)
|| (nib2 = nibble[*s - '0']) == 0xff) { || (nib2 = nibble[*s - '0']) == 0xff) {
errno = EINVAL; errno = EINVAL;
......
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