|
|
8b2c89 |
commit d0b24860363a3704e28569ce9a6987717834edea
|
|
|
8b2c89 |
Author: Miroslav Lichvar <mlichvar@redhat.com>
|
|
|
8b2c89 |
Date: Tue Dec 5 11:08:24 2017 +0100
|
|
|
8b2c89 |
|
|
|
8b2c89 |
client: don't call select() with invalid timeout
|
|
|
8b2c89 |
|
|
|
8b2c89 |
If the system clock was stepped forward after chronyc sent a request and
|
|
|
8b2c89 |
before it read the clock in order to calculate the receive timeout,
|
|
|
8b2c89 |
select() could be called with a negative timeout, which resulted in an
|
|
|
8b2c89 |
infinite loop waiting for select() to succeed.
|
|
|
8b2c89 |
|
|
|
8b2c89 |
Fix the submit_request() function to not call select() with a negative
|
|
|
8b2c89 |
timeout. Also, return immediately on any error of select().
|
|
|
8b2c89 |
|
|
|
8b2c89 |
diff --git a/client.c b/client.c
|
|
|
8b2c89 |
index 5c3a99e..4e23158 100644
|
|
|
8b2c89 |
--- a/client.c
|
|
|
8b2c89 |
+++ b/client.c
|
|
|
8b2c89 |
@@ -1394,9 +1394,16 @@ submit_request(CMD_Request *request, CMD_Reply *reply)
|
|
|
8b2c89 |
|
|
|
8b2c89 |
timeout = initial_timeout / 1000.0 * (1U << (n_attempts - 1)) -
|
|
|
8b2c89 |
UTI_DiffTimespecsToDouble(&ts_now, &ts_start);
|
|
|
8b2c89 |
- UTI_DoubleToTimeval(timeout, &tv;;
|
|
|
8b2c89 |
DEBUG_LOG("Timeout %f seconds", timeout);
|
|
|
8b2c89 |
|
|
|
8b2c89 |
+ /* Avoid calling select() with an invalid timeout */
|
|
|
8b2c89 |
+ if (timeout <= 0.0) {
|
|
|
8b2c89 |
+ new_attempt = 1;
|
|
|
8b2c89 |
+ continue;
|
|
|
8b2c89 |
+ }
|
|
|
8b2c89 |
+
|
|
|
8b2c89 |
+ UTI_DoubleToTimeval(timeout, &tv;;
|
|
|
8b2c89 |
+
|
|
|
8b2c89 |
FD_ZERO(&rdfd);
|
|
|
8b2c89 |
FD_ZERO(&wrfd);
|
|
|
8b2c89 |
FD_ZERO(&exfd);
|
|
|
8b2c89 |
@@ -1410,6 +1417,7 @@ submit_request(CMD_Request *request, CMD_Reply *reply)
|
|
|
8b2c89 |
|
|
|
8b2c89 |
if (select_status < 0) {
|
|
|
8b2c89 |
DEBUG_LOG("select failed : %s", strerror(errno));
|
|
|
8b2c89 |
+ return 0;
|
|
|
8b2c89 |
} else if (select_status == 0) {
|
|
|
8b2c89 |
/* Timeout must have elapsed, try a resend? */
|
|
|
8b2c89 |
new_attempt = 1;
|