mirror of
https://github.com/curl/curl.git
synced 2026-08-25 12:13:37 +03:00
tool_urlglob: make multiply() bail out on negative values
- Does not work correctly with negative values - use __builtin_mul_overflow() on gcc Reported-by: Torben Dury Closes #12102
This commit is contained in:
parent
732d8ef758
commit
8a45a495af
1 changed files with 15 additions and 6 deletions
|
|
@ -66,13 +66,22 @@ static CURLcode glob_fixed(struct URLGlob *glob, char *fixed, size_t len)
|
|||
*/
|
||||
static int multiply(curl_off_t *amount, curl_off_t with)
|
||||
{
|
||||
curl_off_t sum = *amount * with;
|
||||
if(!with) {
|
||||
*amount = 0;
|
||||
return 0;
|
||||
curl_off_t sum;
|
||||
DEBUGASSERT(*amount >= 0);
|
||||
DEBUGASSERT(with >= 0);
|
||||
if((with <= 0) || (*amount <= 0)) {
|
||||
sum = 0;
|
||||
}
|
||||
else {
|
||||
#ifdef __GNUC__
|
||||
if(__builtin_mul_overflow(*amount, with, &sum))
|
||||
return 1;
|
||||
#else
|
||||
sum = *amount * with;
|
||||
if(sum/with != *amount)
|
||||
return 1; /* didn't fit, bail out */
|
||||
#endif
|
||||
}
|
||||
if(sum/with != *amount)
|
||||
return 1; /* didn't fit, bail out */
|
||||
*amount = sum;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue