summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Bursa <james@netsurf-browser.org>2005-01-01 22:27:05 +0000
committerJames Bursa <james@netsurf-browser.org>2005-01-01 22:27:05 +0000
commit143d756fcf681c15b82f117f95a1c527389b0177 (patch)
treed69b872370f158e82312e20851cdebdd9147ce89
parent7824e830cff9ed5c4b4a28a7051994c7c471143f (diff)
downloadnetsurf-143d756fcf681c15b82f117f95a1c527389b0177.tar.gz
netsurf-143d756fcf681c15b82f117f95a1c527389b0177.tar.bz2
[project @ 2005-01-01 22:26:34 by bursa]
xcalloc/xrealloc/xstrdup-purge week. svn path=/import/netsurf/; revision=1418
-rw-r--r--content/fetchcache.c52
1 files changed, 41 insertions, 11 deletions
diff --git a/content/fetchcache.c b/content/fetchcache.c
index 54fd7e1c8..bdc04eb29 100644
--- a/content/fetchcache.c
+++ b/content/fetchcache.c
@@ -210,6 +210,14 @@ void fetchcache_callback(fetch_msg msg, void *p, const char *data,
case FETCH_TYPE:
c->total_size = size;
mime_type = fetchcache_parse_type(data, &params);
+ if (!mime_type) {
+ msg_data.error = messages_get("NoMemory");
+ content_broadcast(c, CONTENT_MSG_ERROR,
+ msg_data);
+ fetch_abort(c->fetch);
+ c->fetch = 0;
+ return;
+ }
type = content_lookup(mime_type);
LOG(("FETCH_TYPE, type %u", type));
res = content_set_type(c, type, mime_type, params);
@@ -330,42 +338,64 @@ void fetchcache_init(void)
/**
* Parse a Content-Type header.
*
- * \param s a Content-Type header
- * \param params updated to point to an array of strings, ordered attribute,
- * value, attribute, ..., 0
- * \return a new string containing the MIME-type
+ * \param s a Content-Type header
+ * \param params updated to point to an array of strings, ordered attribute,
+ * value, attribute, ..., 0
+ * \return a new string containing the MIME-type, or 0 on memory exhaustion
*/
#define MAX_ATTRS 10
char *fetchcache_parse_type(const char *s, char **params[])
{
- char *type;
+ char *type = 0;
unsigned int i;
int r;
regmatch_t pmatch[2 + MAX_ATTRS * 3];
- *params = xcalloc(MAX_ATTRS * 2 + 2, sizeof (*params)[0]);
+
+ *params = malloc((MAX_ATTRS * 2 + 2) * sizeof (*params)[0]);
+ if (!*params)
+ goto no_memory;
+ for (i = 0; i != MAX_ATTRS * 2 + 2; i++)
+ (*params)[i] = 0;
r = regexec(&re_content_type, s, 2 + MAX_ATTRS * 3, pmatch, 0);
if (r) {
LOG(("failed to parse content-type '%s'", s));
- return xstrdup(s);
+ type = strdup(s);
+ if (!type)
+ goto no_memory;
+ return type;
}
type = strndup(s + pmatch[1].rm_so, pmatch[1].rm_eo - pmatch[1].rm_so);
- assert(type);
+ if (!type) {
+ free(*params);
+ return 0;
+ }
/* parameters */
for (i = 0; i != MAX_ATTRS && pmatch[2 + 3 * i].rm_so != -1; i++) {
(*params)[2 * i] = strndup(s + pmatch[2 + 3 * i + 1].rm_so,
- pmatch[2 + 3 * i + 1].rm_eo - pmatch[2 + 3 * i + 1].rm_so);
+ pmatch[2 + 3 * i + 1].rm_eo -
+ pmatch[2 + 3 * i + 1].rm_so);
(*params)[2 * i + 1] = strndup(s + pmatch[2 + 3 * i + 2].rm_so,
- pmatch[2 + 3 * i + 2].rm_eo - pmatch[2 + 3 * i + 2].rm_so);
- assert((*params)[2 * i] && (*params)[2 * i + 1]);
+ pmatch[2 + 3 * i + 2].rm_eo -
+ pmatch[2 + 3 * i + 2].rm_so);
+ if (!(*params)[2 * i] || !(*params)[2 * i + 1])
+ goto no_memory;
}
(*params)[2 * i] = 0;
return type;
+
+no_memory:
+ for (i = 0; i != MAX_ATTRS * 2 + 2; i++)
+ free((*params)[i]);
+ free(*params);
+ free(type);
+
+ return 0;
}