summaryrefslogtreecommitdiff
path: root/lib/parsedate.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2019-11-28 15:27:58 +0100
committerDaniel Stenberg <daniel@haxx.se>2019-11-29 11:01:24 +0100
commit0044443a020d15c262e9f6c724b29365a8148437 (patch)
treef345ffb8bf4a275caa823b758ccac35bbf6f3526 /lib/parsedate.c
parentbc64377ff8386d4f809806b6286f43e5aff19922 (diff)
downloadcurl-0044443a020d15c262e9f6c724b29365a8148437.tar.gz
parsedate: offer a getdate_capped() alternative
... and use internally. This function will return TIME_T_MAX instead of failure if the parsed data is found to be larger than what can be represented. TIME_T_MAX being the largest value curl can represent. Reviewed-by: Daniel Gustafsson Reported-by: JanB on github Fixes #4152 Closes #4651
Diffstat (limited to 'lib/parsedate.c')
-rw-r--r--lib/parsedate.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/parsedate.c b/lib/parsedate.c
index f4b18d091..585d7ea40 100644
--- a/lib/parsedate.c
+++ b/lib/parsedate.c
@@ -587,6 +587,30 @@ time_t curl_getdate(const char *p, const time_t *now)
return -1;
}
+/* Curl_getdate_capped() differs from curl_getdate() in that this will return
+ TIME_T_MAX in case the parsed time value was too big, instead of an
+ error. */
+
+time_t Curl_getdate_capped(const char *p)
+{
+ time_t parsed = -1;
+ int rc = parsedate(p, &parsed);
+
+ switch(rc) {
+ case PARSEDATE_OK:
+ if(parsed == -1)
+ /* avoid returning -1 for a working scenario */
+ parsed++;
+ return parsed;
+ case PARSEDATE_LATER:
+ /* this returns the maximum time value */
+ return parsed;
+ default:
+ return -1; /* everything else is fail */
+ }
+ /* UNREACHABLE */
+}
+
/*
* Curl_gmtime() is a gmtime() replacement for portability. Do not use the
* gmtime_r() or gmtime() functions anywhere else but here.