summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2019-11-09 17:06:04 +0000
committerMichael Drake <tlsa@netsurf-browser.org>2019-11-09 17:06:04 +0000
commitb15cbb72ac882cf820dd0db80238594a44f0ed00 (patch)
treeb71747dfcc42783476ece2184a3e5b4efd185fb5
parentc92b31babea9f34a1987f99ce20a4c7b067f9b68 (diff)
downloadnetsurf-b15cbb72ac882cf820dd0db80238594a44f0ed00.tar.gz
netsurf-b15cbb72ac882cf820dd0db80238594a44f0ed00.tar.bz2
File fetcher: Avoid atoi for If-None-Match value parse.
The file fetcher emits FETCH_NOTMODIFIED if the file is unchanged.
-rw-r--r--content/fetchers/file.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/content/fetchers/file.c b/content/fetchers/file.c
index 4fa1a2138..5c9d15837 100644
--- a/content/fetchers/file.c
+++ b/content/fetchers/file.c
@@ -50,6 +50,8 @@
#include "utils/corestrings.h"
#include "utils/messages.h"
#include "utils/utils.h"
+#include "utils/log.h"
+#include "utils/time.h"
#include "utils/ring.h"
#include "utils/file.h"
#include "netsurf/fetch.h"
@@ -156,18 +158,25 @@ fetch_file_setup(struct fetch *fetchh,
/* Scan request headers looking for If-None-Match */
for (i = 0; headers[i] != NULL; i++) {
- if (strncasecmp(headers[i], "If-None-Match:",
- SLEN("If-None-Match:")) == 0) {
- /* If-None-Match: "12345678" */
- const char *d = headers[i] + SLEN("If-None-Match:");
-
- /* Scan to first digit, if any */
- while (*d != '\0' && (*d < '0' || '9' < *d))
- d++;
-
- /* Convert to time_t */
- if (*d != '\0')
- ctx->file_etag = atoi(d);
+ if (strncasecmp(headers[i], "If-None-Match:",
+ SLEN("If-None-Match:")) != 0) {
+ continue;
+ }
+
+ /* If-None-Match: "12345678" */
+ const char *d = headers[i] + SLEN("If-None-Match:");
+
+ /* Scan to first digit, if any */
+ while (*d != '\0' && (*d < '0' || '9' < *d))
+ d++;
+
+ /* Convert to time_t */
+ if (*d != '\0') {
+ ret = nsc_snptimet(d, strlen(d), &ctx->file_etag);
+ if (ret != NSERROR_OK) {
+ NSLOG(fetch, WARNING,
+ "Bad If-None-Match value");
+ }
}
}