Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <20221230032132.14003-1-AWilcox@Wilcox-Tech.com>
Date: Thu, 29 Dec 2022 21:21:32 -0600
From: "A. Wilcox" <AWilcox@...cox-Tech.com>
To: musl@...ts.openwall.com
Cc: "A. Wilcox" <AWilcox@...cox-Tech.com>
Subject: [PATCH] dns: Prefer monotonic clock for DNS lookup timeouts

Before this commit, DNS timeouts always used CLOCK_REALTIME, which could
produce errors if wall time changed for whatever reason.

Now we try CLOCK_MONOTONIC and only fall back to CLOCK_REALTIME when it
is unavailable.
---
 src/network/res_msend.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/network/res_msend.c b/src/network/res_msend.c
index 11c6aa0e..fef7e3a2 100644
--- a/src/network/res_msend.c
+++ b/src/network/res_msend.c
@@ -25,7 +25,8 @@ static void cleanup(void *p)
 static unsigned long mtime()
 {
 	struct timespec ts;
-	clock_gettime(CLOCK_REALTIME, &ts);
+	if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0 && errno == ENOSYS)
+		clock_gettime(CLOCK_REALTIME, &ts);
 	return (unsigned long)ts.tv_sec * 1000
 		+ ts.tv_nsec / 1000000;
 }
-- 
2.37.1 (Apple Git-137.1)

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.