unescape: avoid integer overflow

CVE-2016-8622

Bug: https://curl.haxx.se/docs/adv_20161102H.html
Reported-by: Cure53
This commit is contained in:
Daniel Stenberg 2016-10-04 18:56:45 +02:00
parent c5be3d7267
commit 53e71e47d6
3 changed files with 18 additions and 9 deletions

View file

@ -224,8 +224,14 @@ char *curl_easy_unescape(struct Curl_easy *data, const char *string,
FALSE);
if(res)
return NULL;
if(olen)
*olen = curlx_uztosi(outputlen);
if(olen) {
if(outputlen <= (size_t) INT_MAX)
*olen = curlx_uztosi(outputlen);
else
/* too large to return in an int, fail! */
Curl_safefree(str);
}
}
return str;
}