]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
openssl: shortcut store_expired for negative timeouts
authorDaniel Stenberg <daniel@haxx.se>
Tue, 11 Jun 2024 06:03:28 +0000 (08:03 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 11 Jun 2024 08:51:00 +0000 (10:51 +0200)
Avoid some unnecessary computation if the timeout is negative.

Spotted by CodeSonar
Closes #13919

lib/vtls/openssl.c

index 95a8526ba3bf3306844ba4c261d620bdfb24a8ca..a7f5f9a032a9f51979b41430e2fc1e1df02f2c17 100644 (file)
@@ -3310,14 +3310,15 @@ cached_x509_store_expired(const struct Curl_easy *data,
                           const struct ossl_x509_share *mb)
 {
   const struct ssl_general_config *cfg = &data->set.general_ssl;
-  struct curltime now = Curl_now();
-  timediff_t elapsed_ms = Curl_timediff(now, mb->time);
-  timediff_t timeout_ms = cfg->ca_cache_timeout * (timediff_t)1000;
-
-  if(timeout_ms < 0)
-    return false;
+  if(cfg->ca_cache_timeout < 0)
+    return FALSE;
+  else {
+    struct curltime now = Curl_now();
+    timediff_t elapsed_ms = Curl_timediff(now, mb->time);
+    timediff_t timeout_ms = cfg->ca_cache_timeout * (timediff_t)1000;
 
-  return elapsed_ms >= timeout_ms;
+    return elapsed_ms >= timeout_ms;
+  }
 }
 
 static bool