Curl_pgrsTime - return new time to avoid timeout integer overflow

Setting a timeout to INT_MAX could cause an immediate error to get
returned as timeout because of an overflow when different values of
'now' were used.

This is primarily fixed by having Curl_pgrsTime() return the "now" when
TIMER_STARTSINGLE is set so that the parent function will continue using
that time.

Reported-by: Ionuț-Francisc Oancea
Fixes #5583
Closes #5847
This commit is contained in:
Daniel Stenberg 2020-08-24 11:07:59 +02:00
parent 68a5132474
commit a2c85bb8e4
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
4 changed files with 27 additions and 23 deletions

View file

@ -164,9 +164,13 @@ void Curl_pgrsResetTransferSizes(struct Curl_easy *data)
}
/*
*
* Curl_pgrsTime(). Store the current time at the given label. This fetches a
* fresh "now" and returns it.
*
* @unittest: 1399
*/
void Curl_pgrsTime(struct Curl_easy *data, timerid timer)
struct curltime Curl_pgrsTime(struct Curl_easy *data, timerid timer)
{
struct curltime now = Curl_now();
timediff_t *delta = NULL;
@ -209,7 +213,7 @@ void Curl_pgrsTime(struct Curl_easy *data, timerid timer)
* changing the t_starttransfer time.
*/
if(data->progress.is_t_startransfer_set) {
return;
return now;
}
else {
data->progress.is_t_startransfer_set = true;
@ -228,6 +232,7 @@ void Curl_pgrsTime(struct Curl_easy *data, timerid timer)
us = 1; /* make sure at least one microsecond passed */
*delta += us;
}
return now;
}
void Curl_pgrsStartNow(struct Curl_easy *data)