parsedate: make Curl_getdate_capped able to return epoch

By returning error separately on parse errors and avoiding magic
numbers, this function can now return 0 or -1 as proper dates when such
a date string is provided.
This commit is contained in:
Daniel Stenberg 2025-09-01 16:36:53 +02:00
parent 63b7d8b8f4
commit 5e27c20870
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
9 changed files with 50 additions and 68 deletions

View file

@ -1855,9 +1855,9 @@ static int myssh_in_SFTP_QUOTE_STAT(struct Curl_easy *data,
}
else if(!strncmp(cmd, "atime", 5) ||
!strncmp(cmd, "mtime", 5)) {
time_t date = Curl_getdate_capped(sshc->quote_path1);
time_t date;
bool fail = FALSE;
if(date == -1) {
if(Curl_getdate_capped(sshc->quote_path1, &date)) {
failf(data, "incorrect date format for %.*s", 5, cmd);
fail = TRUE;
}

View file

@ -1390,16 +1390,16 @@ sftp_quote_stat(struct Curl_easy *data,
}
else if(!strncmp(cmd, "atime", 5) ||
!strncmp(cmd, "mtime", 5)) {
time_t date = Curl_getdate_capped(sshc->quote_path1);
time_t date;
bool fail = FALSE;
if(date == -1) {
if(Curl_getdate_capped(sshc->quote_path1, &date)) {
failf(data, "incorrect date format for %.*s", 5, cmd);
fail = TRUE;
}
#if SIZEOF_TIME_T > SIZEOF_LONG
if(date > 0xffffffff) {
/* if 'long' cannot old >32-bit, this date cannot be sent */
/* if 'long' cannot hold >32-bit, this date cannot be sent */
failf(data, "date overflow");
fail = TRUE;
}