summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2023-05-09 10:01:52 +0200
committerDaniel Stenberg <daniel@haxx.se>2023-05-09 17:56:19 +0200
commit8e6abece403f162946d360c1871e2251f124a637 (patch)
tree6b9f97276d1eaeddff19e11d58d9ff77da9d441f
parentf7170a8f2ed4dc5a4cfb3ef3c002d218c4bcecad (diff)
downloadcurl-8e6abece403f162946d360c1871e2251f124a637.tar.gz
hostip: use time_t for storing oldest DNS entry
Theoretically, the oldest time could overflow an int. In practice that won't happen, but let's do this to please analyzers. Follow-up to 9ed7d56e044f5aa1b2928ccde6245d0 Pointed out by Coverity. Closes #11094
-rw-r--r--lib/hostip.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/hostip.c b/lib/hostip.c
index 50e483013..615f36c16 100644
--- a/lib/hostip.c
+++ b/lib/hostip.c
@@ -199,8 +199,8 @@ create_hostcache_id(const char *name,
struct hostcache_prune_data {
time_t now;
+ time_t oldest; /* oldest time in cache not pruned. */
int cache_timeout;
- int oldest; /* oldest time in cache not pruned */
};
/*
@@ -223,7 +223,7 @@ hostcache_timestamp_remove(void *datap, void *hc)
if(age >= prune->cache_timeout)
return TRUE;
if(age > prune->oldest)
- prune->oldest = (int)age;
+ prune->oldest = age;
}
return FALSE;
}
@@ -232,8 +232,9 @@ hostcache_timestamp_remove(void *datap, void *hc)
* Prune the DNS cache. This assumes that a lock has already been taken.
* Returns the 'age' of the oldest still kept entry.
*/
-static int
-hostcache_prune(struct Curl_hash *hostcache, int cache_timeout, time_t now)
+static time_t
+hostcache_prune(struct Curl_hash *hostcache, int cache_timeout,
+ time_t now)
{
struct hostcache_prune_data user;
@@ -269,9 +270,12 @@ void Curl_hostcache_prune(struct Curl_easy *data)
do {
/* Remove outdated and unused entries from the hostcache */
- int oldest = hostcache_prune(data->dns.hostcache, timeout, now);
+ time_t oldest = hostcache_prune(data->dns.hostcache, timeout, now);
- timeout = oldest;
+ if(oldest < INT_MAX)
+ timeout = (int)oldest; /* we know it fits */
+ else
+ timeout = INT_MAX - 1;
/* if the cache size is still too big, use the oldest age as new
prune limit */