1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-21 23:58:49 -05:00

Curl_timeleft: change return type to timediff_t

returning 'time_t' is problematic when that type is unsigned and we
return values less than zero to signal "already expired", used in
several places in the code.

Closes #2021
This commit is contained in:
Daniel Stenberg 2017-10-26 15:24:50 +02:00
parent 9dfc541dd7
commit 0d85eed3df
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
9 changed files with 19 additions and 18 deletions

View File

@ -354,7 +354,7 @@ CURLcode Curl_resolver_wait_resolv(struct connectdata *conn,
{ {
CURLcode result = CURLE_OK; CURLcode result = CURLE_OK;
struct Curl_easy *data = conn->data; struct Curl_easy *data = conn->data;
long timeout; timediff_t timeout;
struct curltime now = Curl_now(); struct curltime now = Curl_now();
struct Curl_dns_entry *temp_entry; struct Curl_dns_entry *temp_entry;

View File

@ -179,12 +179,12 @@ singleipconnect(struct connectdata *conn,
* *
* @unittest: 1303 * @unittest: 1303
*/ */
time_t Curl_timeleft(struct Curl_easy *data, timediff_t Curl_timeleft(struct Curl_easy *data,
struct curltime *nowp, struct curltime *nowp,
bool duringconnect) bool duringconnect)
{ {
int timeout_set = 0; int timeout_set = 0;
time_t timeout_ms = duringconnect?DEFAULT_CONNECT_TIMEOUT:0; timediff_t timeout_ms = duringconnect?DEFAULT_CONNECT_TIMEOUT:0;
struct curltime now; struct curltime now;
/* if a timeout is set, use the most restrictive one */ /* if a timeout is set, use the most restrictive one */
@ -1148,7 +1148,7 @@ CURLcode Curl_connecthost(struct connectdata *conn, /* context */
struct curltime before = Curl_now(); struct curltime before = Curl_now();
CURLcode result = CURLE_COULDNT_CONNECT; CURLcode result = CURLE_COULDNT_CONNECT;
time_t timeout_ms = Curl_timeleft(data, &before, TRUE); timediff_t timeout_ms = Curl_timeleft(data, &before, TRUE);
if(timeout_ms < 0) { if(timeout_ms < 0) {
/* a precaution, no need to continue if time already is up */ /* a precaution, no need to continue if time already is up */

View File

@ -25,6 +25,7 @@
#include "nonblock.h" /* for curlx_nonblock(), formerly Curl_nonblock() */ #include "nonblock.h" /* for curlx_nonblock(), formerly Curl_nonblock() */
#include "sockaddr.h" #include "sockaddr.h"
#include "timeval.h"
CURLcode Curl_is_connected(struct connectdata *conn, CURLcode Curl_is_connected(struct connectdata *conn,
int sockindex, int sockindex,
@ -35,7 +36,7 @@ CURLcode Curl_connecthost(struct connectdata *conn,
/* generic function that returns how much time there's left to run, according /* generic function that returns how much time there's left to run, according
to the timeouts set */ to the timeouts set */
time_t Curl_timeleft(struct Curl_easy *data, timediff_t Curl_timeleft(struct Curl_easy *data,
struct curltime *nowp, struct curltime *nowp,
bool duringconnect); bool duringconnect);

View File

@ -333,10 +333,10 @@ static CURLcode AcceptServerConnect(struct connectdata *conn)
* Curl_pgrsTime(..., TIMER_STARTACCEPT); * Curl_pgrsTime(..., TIMER_STARTACCEPT);
* *
*/ */
static time_t ftp_timeleft_accept(struct Curl_easy *data) static timediff_t ftp_timeleft_accept(struct Curl_easy *data)
{ {
time_t timeout_ms = DEFAULT_ACCEPT_TIMEOUT; timediff_t timeout_ms = DEFAULT_ACCEPT_TIMEOUT;
time_t other; timediff_t other;
struct curltime now; struct curltime now;
if(data->set.accepttimeout > 0) if(data->set.accepttimeout > 0)

View File

@ -1318,7 +1318,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
struct SingleRequest *k; struct SingleRequest *k;
time_t timeout_ms; time_t timeout_ms;
time_t recv_timeout_ms; time_t recv_timeout_ms;
time_t send_timeout_ms; timediff_t send_timeout_ms;
int control; int control;
if(!GOOD_EASY_HANDLE(data)) if(!GOOD_EASY_HANDLE(data))

View File

@ -57,7 +57,7 @@ int Curl_blockread_all(struct connectdata *conn, /* connection data */
ssize_t nread; ssize_t nread;
ssize_t allread = 0; ssize_t allread = 0;
int result; int result;
time_t timeleft; timediff_t timeleft;
*n = 0; *n = 0;
for(;;) { for(;;) {
timeleft = Curl_timeleft(conn->data, NULL, TRUE); timeleft = Curl_timeleft(conn->data, NULL, TRUE);
@ -382,7 +382,7 @@ CURLcode Curl_SOCKS5(const char *proxy_user,
CURLcode code; CURLcode code;
curl_socket_t sock = conn->sock[sockindex]; curl_socket_t sock = conn->sock[sockindex];
struct Curl_easy *data = conn->data; struct Curl_easy *data = conn->data;
time_t timeout; timediff_t timeout;
bool socks5_resolve_local = bool socks5_resolve_local =
(conn->socks_proxy.proxytype == CURLPROXY_SOCKS5) ? TRUE : FALSE; (conn->socks_proxy.proxytype == CURLPROXY_SOCKS5) ? TRUE : FALSE;
const size_t hostname_len = strlen(hostname); const size_t hostname_len = strlen(hostname);

View File

@ -2833,7 +2833,7 @@ static CURLcode ssh_block_statemach(struct connectdata *conn,
while((sshc->state != SSH_STOP) && !result) { while((sshc->state != SSH_STOP) && !result) {
bool block; bool block;
time_t left = 1000; timediff_t left = 1000;
struct curltime now = Curl_now(); struct curltime now = Curl_now();
result = ssh_statemach_act(conn, &block); result = ssh_statemach_act(conn, &block);

View File

@ -200,7 +200,7 @@ const struct Curl_handler Curl_handler_tftp = {
static CURLcode tftp_set_timeouts(tftp_state_data_t *state) static CURLcode tftp_set_timeouts(tftp_state_data_t *state)
{ {
time_t maxtime, timeout; time_t maxtime, timeout;
time_t timeout_ms; timediff_t timeout_ms;
bool start = (state->state == TFTP_STATE_START) ? TRUE : FALSE; bool start = (state->state == TFTP_STATE_START) ? TRUE : FALSE;
time(&state->start_time); time(&state->start_time);

View File

@ -6323,7 +6323,7 @@ static CURLcode resolve_server(struct Curl_easy *data,
bool *async) bool *async)
{ {
CURLcode result = CURLE_OK; CURLcode result = CURLE_OK;
time_t timeout_ms = Curl_timeleft(data, NULL, TRUE); timediff_t timeout_ms = Curl_timeleft(data, NULL, TRUE);
/************************************************************* /*************************************************************
* Resolve the name of the server or proxy * Resolve the name of the server or proxy