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

tftp: remove the 3600 second default timeout

... it was never meant to be there.

Reported-by: Tomas Berger
Fixes #6774
Closes #6776
This commit is contained in:
Daniel Stenberg 2021-03-22 15:39:27 +01:00
parent d7f737dd13
commit d3d90ad9c0
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View File

@ -217,35 +217,20 @@ static CURLcode tftp_set_timeouts(struct tftp_state_data *state)
return CURLE_OPERATION_TIMEDOUT; return CURLE_OPERATION_TIMEDOUT;
} }
if(start) { /* timeout in milliseconds */
state->max_time = timeout_ms;
if(timeout_ms > 0)
maxtime = (time_t)(timeout_ms + 500) / 1000; maxtime = (time_t)(timeout_ms + 500) / 1000;
state->max_time = state->start_time + maxtime; else
maxtime = 3600; /* use for calculating block timeouts */
/* Set per-block timeout to total */ /* Set per-block timeout to total */
timeout = maxtime; timeout = maxtime;
/* Average restart after 5 seconds */ /* Average reposting an ACK after 5 seconds */
state->retry_max = (int)timeout/5; state->retry_max = (int)timeout/5;
if(state->retry_max < 1)
/* avoid division by zero below */
state->retry_max = 1;
}
else {
if(timeout_ms > 0)
maxtime = (time_t)(timeout_ms + 500) / 1000;
else
maxtime = 3600;
state->max_time = state->start_time + maxtime;
/* Set per-block timeout to total */
timeout = maxtime;
/* Average reposting an ACK after 5 seconds */
state->retry_max = (int)timeout/5;
}
/* But bound the total number */ /* But bound the total number */
if(state->retry_max<3) if(state->retry_max<3)
state->retry_max = 3; state->retry_max = 3;
@ -259,9 +244,9 @@ static CURLcode tftp_set_timeouts(struct tftp_state_data *state)
state->retry_time = 1; state->retry_time = 1;
infof(state->data, infof(state->data,
"set timeouts for state %d; Total %ld, retry %d maxtry %d\n", "set timeouts for state %d; Total % " CURL_FORMAT_CURL_OFF_T
(int)state->state, (long)(state->max_time-state->start_time), ", retry %d maxtry %d\n",
state->retry_time, state->retry_max); (int)state->state, timeout_ms, state->retry_time, state->retry_max);
/* init RX time */ /* init RX time */
time(&state->rx_time); time(&state->rx_time);
@ -1209,33 +1194,32 @@ static CURLcode tftp_receive_packet(struct Curl_easy *data)
* Check if timeouts have been reached * Check if timeouts have been reached
* *
**********************************************************/ **********************************************************/
static long tftp_state_timeout(struct Curl_easy *data, tftp_event_t *event) static timediff_t tftp_state_timeout(struct Curl_easy *data,
tftp_event_t *event)
{ {
time_t current; time_t current;
struct connectdata *conn = data->conn; struct connectdata *conn = data->conn;
struct tftp_state_data *state = conn->proto.tftpc; struct tftp_state_data *state = conn->proto.tftpc;
timediff_t timeout_ms;
if(event) if(event)
*event = TFTP_EVENT_NONE; *event = TFTP_EVENT_NONE;
time(&current); timeout_ms = Curl_timeleft(state->data, NULL,
if(current > state->max_time) { (state->state == TFTP_STATE_START));
DEBUGF(infof(data, "timeout: %ld > %ld\n", if(timeout_ms < 0) {
(long)current, (long)state->max_time));
state->error = TFTP_ERR_TIMEOUT; state->error = TFTP_ERR_TIMEOUT;
state->state = TFTP_STATE_FIN; state->state = TFTP_STATE_FIN;
return 0; return 0;
} }
time(&current);
if(current > state->rx_time + state->retry_time) { if(current > state->rx_time + state->retry_time) {
if(event) if(event)
*event = TFTP_EVENT_TIMEOUT; *event = TFTP_EVENT_TIMEOUT;
time(&state->rx_time); /* update even though we received nothing */ time(&state->rx_time); /* update even though we received nothing */
} }
/* there's a typecast below here since 'time_t' may in fact be larger than return timeout_ms;
'long', but we estimate that a 'long' will still be able to hold number
of seconds even if "only" 32 bit */
return (long)(state->max_time - current);
} }
/********************************************************** /**********************************************************
@ -1251,11 +1235,11 @@ static CURLcode tftp_multi_statemach(struct Curl_easy *data, bool *done)
CURLcode result = CURLE_OK; CURLcode result = CURLE_OK;
struct connectdata *conn = data->conn; struct connectdata *conn = data->conn;
struct tftp_state_data *state = conn->proto.tftpc; struct tftp_state_data *state = conn->proto.tftpc;
long timeout_ms = tftp_state_timeout(data, &event); timediff_t timeout_ms = tftp_state_timeout(data, &event);
*done = FALSE; *done = FALSE;
if(timeout_ms <= 0) { if(timeout_ms < 0) {
failf(data, "TFTP response timeout"); failf(data, "TFTP response timeout");
return CURLE_OPERATION_TIMEDOUT; return CURLE_OPERATION_TIMEDOUT;
} }