]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
libssh: setting atime or mtime > 32bit is now just skipped
authorDaniel Stenberg <daniel@haxx.se>
Tue, 16 Aug 2022 14:22:51 +0000 (16:22 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 16 Aug 2022 21:15:57 +0000 (23:15 +0200)
The libssh API used caps the time to an unsigned 32bit variable. Avoid
nasty surprises by instead not setting such time.

Spotted by Coverity.

Closes #9324

lib/vssh/libssh.c

index 5aa99e618b2a923adc36a6149374abc404cc9844..c2f71d030541709892bc413911dca76e7755963a 100644 (file)
@@ -2922,8 +2922,15 @@ static void sftp_quote_stat(struct Curl_easy *data)
       sshc->actualcode = CURLE_QUOTE_ERROR;
       return;
     }
-    sshc->quote_attrs->atime = (uint32_t)date;
-    sshc->quote_attrs->flags |= SSH_FILEXFER_ATTR_ACMODTIME;
+#if SIZEOF_TIME_T > 4
+    if(date > 0xffffffff)
+      ; /* avoid setting a capped time */
+    else
+#endif
+    {
+      sshc->quote_attrs->atime = (uint32_t)date;
+      sshc->quote_attrs->flags |= SSH_FILEXFER_ATTR_ACMODTIME;
+    }
   }
   else if(strncasecompare(cmd, "mtime", 5)) {
     time_t date = Curl_getdate_capped(sshc->quote_path1);
@@ -2936,8 +2943,15 @@ static void sftp_quote_stat(struct Curl_easy *data)
       sshc->actualcode = CURLE_QUOTE_ERROR;
       return;
     }
-    sshc->quote_attrs->mtime = (uint32_t)date;
-    sshc->quote_attrs->flags |= SSH_FILEXFER_ATTR_ACMODTIME;
+#if SIZEOF_TIME_T > 4
+    if(date > 0xffffffff)
+      ; /* avoid setting a capped time */
+    else
+#endif
+    {
+      sshc->quote_attrs->mtime = (uint32_t)date;
+      sshc->quote_attrs->flags |= SSH_FILEXFER_ATTR_ACMODTIME;
+    }
   }
 
   /* Now send the completed structure... */