summaryrefslogtreecommitdiff
path: root/content/fetchcache.c
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2009-03-02 20:32:05 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2009-03-02 20:32:05 +0000
commita36535f341842767e3d6f2f68052bf5005f7ffd4 (patch)
tree14a89dca253417457e1dcd90e984e74b92d6efc1 /content/fetchcache.c
parent7840542e65b694f251e15ca5d247b9ede25d9f89 (diff)
downloadnetsurf-a36535f341842767e3d6f2f68052bf5005f7ffd4.tar.gz
netsurf-a36535f341842767e3d6f2f68052bf5005f7ffd4.tar.bz2
Pointless warning avoidance.
svn path=/trunk/netsurf/; revision=6676
Diffstat (limited to 'content/fetchcache.c')
-rw-r--r--content/fetchcache.c33
1 files changed, 22 insertions, 11 deletions
diff --git a/content/fetchcache.c b/content/fetchcache.c
index 390c092b6..45aa9748e 100644
--- a/content/fetchcache.c
+++ b/content/fetchcache.c
@@ -104,22 +104,28 @@ struct content * fetchcache(const char *url,
if (strncasecmp(url, "file:///", 8) &&
strncasecmp(url, "file:/", 6) == 0) {
/* Manipulate file URLs into correct format */
- if (strncasecmp(url, "file://", 7) == 0) {
+ int len = strlen(url) + 1;
+
+ if (strncasecmp(url, "file://", SLEN("file://")) == 0) {
/* file://path */
- url1 = malloc(7 + strlen(url));
+ url1 = malloc(len + 1 /* + '/' */);
if (!url1)
return NULL;
- strcpy(url1, "file://");
- strcat(url1 + 7, url + 6);
+ memcpy(url1, "file:///", SLEN("file:///"));
+ memcpy(url1 + SLEN("file:///"),
+ url + SLEN("file://"),
+ len - SLEN("file://"));
} else {
/* file:/... */
- url1 = malloc(7 + strlen(url));
+ url1 = malloc(len + 2 /* + "//" */);
if (!url1)
return NULL;
- strcpy(url1, "file://");
- strcat(url1 + 7, url + 5);
+ memcpy(url1, "file:///", SLEN("file:///"));
+ memcpy(url1 + SLEN("file:///"),
+ url + SLEN("file:/"),
+ len - SLEN("file:/"));
}
} else {
/* simply duplicate the URL */
@@ -304,7 +310,9 @@ void fetchcache_go(struct content *content, const char *referer,
return;
}
if (etag) {
- headers[i] = malloc(15 + strlen(etag) + 1);
+ int len = SLEN("If-None-Match: ") + strlen(etag) + 1;
+
+ headers[i] = malloc(len);
if (!headers[i]) {
free(headers);
content->status = CONTENT_STATUS_ERROR;
@@ -313,11 +321,14 @@ void fetchcache_go(struct content *content, const char *referer,
msg_data);
return;
}
- sprintf(headers[i++], "If-None-Match: %s", etag);
+ snprintf(headers[i++], len, "If-None-Match: %s", etag);
talloc_free(etag);
}
if (date) {
- headers[i] = malloc(19 + 29 + 1);
+ /* Maximum length of an RFC 1123 date is 29 bytes */
+ int len = SLEN("If-Modified-Since: ") + 29 + 1;
+
+ headers[i] = malloc(len);
if (!headers[i]) {
while (--i >= 0) {
free(headers[i]);
@@ -329,7 +340,7 @@ void fetchcache_go(struct content *content, const char *referer,
msg_data);
return;
}
- sprintf(headers[i++], "If-Modified-Since: %s",
+ snprintf(headers[i++], len, "If-Modified-Since: %s",
rfc1123_date(date));
}
headers[i] = 0;