]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
smb: avoid integer overflow on weird input date
authorDaniel Stenberg <daniel@haxx.se>
Mon, 28 Apr 2025 11:35:02 +0000 (13:35 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 28 Apr 2025 13:29:59 +0000 (15:29 +0200)
Found by OSS-fuzz

Closes #17206

lib/smb.c

index 164b7951d83edc9a569ec39e644e080b201cf9cb..b25edf8ae3d9f671282e3b201d6beb93d316f94b 100644 (file)
--- a/lib/smb.c
+++ b/lib/smb.c
@@ -926,16 +926,20 @@ static CURLcode smb_connection_state(struct Curl_easy *data, bool *done)
  */
 static void get_posix_time(time_t *out, curl_off_t timestamp)
 {
-  timestamp -= CURL_OFF_T_C(116444736000000000);
-  timestamp /= 10000000;
+  if(timestamp >= CURL_OFF_T_C(116444736000000000)) {
+    timestamp -= CURL_OFF_T_C(116444736000000000);
+    timestamp /= 10000000;
 #if SIZEOF_TIME_T < SIZEOF_CURL_OFF_T
-  if(timestamp > TIME_T_MAX)
-    *out = TIME_T_MAX;
-  else if(timestamp < TIME_T_MIN)
-    *out = TIME_T_MIN;
-  else
+    if(timestamp > TIME_T_MAX)
+      *out = TIME_T_MAX;
+    else if(timestamp < TIME_T_MIN)
+      *out = TIME_T_MIN;
+    else
 #endif
-    *out = (time_t) timestamp;
+      *out = (time_t) timestamp;
+  }
+  else
+    *out = 0;
 }
 
 static CURLcode smb_request_state(struct Curl_easy *data, bool *done)