From 44a02d2532c4e6dabb8f2a074d52d5e99ff533be Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 16 Aug 2022 16:22:51 +0200 Subject: [PATCH] libssh: setting atime or mtime > 32bit is now just skipped 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 | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/vssh/libssh.c b/lib/vssh/libssh.c index 5aa99e618b..c2f71d0305 100644 --- a/lib/vssh/libssh.c +++ b/lib/vssh/libssh.c @@ -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... */ -- 2.47.3