summaryrefslogtreecommitdiff
path: root/http.c
diff options
context:
space:
mode:
authorJardel Weyrich <jweyrich@gmail.com>2010-12-18 01:07:27 -0200
committerNick Mathewson <nickm@torproject.org>2011-01-07 13:03:31 -0500
commit666b09669187daad7107b340dd7dde50070a2feb (patch)
tree78ad3ded150b73569ed13d000c2f42c4c67daa39 /http.c
parent0144886e7e9fdfb5dc630dcf0567846b952994bd (diff)
downloadlibevent-666b09669187daad7107b340dd7dde50070a2feb.tar.gz
Detect and handle more allocation failures.
Diffstat (limited to 'http.c')
-rw-r--r--http.c44
1 files changed, 41 insertions, 3 deletions
diff --git a/http.c b/http.c
index f8de3b37..60ea21ee 100644
--- a/http.c
+++ b/http.c
@@ -2491,6 +2491,10 @@ evhttp_response_code(struct evhttp_request *req, int code, const char *reason)
if (reason == NULL)
reason = evhttp_response_phrase_internal(code);
req->response_code_line = mm_strdup(reason);
+ if (req->response_code_line == NULL) {
+ event_warn("%s: strdup", __func__);
+ /* XXX what else can we do? */
+ }
}
void
@@ -3280,6 +3284,11 @@ evhttp_set_cb(struct evhttp *http, const char *uri,
}
http_cb->what = mm_strdup(uri);
+ if (http_cb->what == NULL) {
+ event_warn("%s: strdup", __func__);
+ mm_free(http_cb);
+ return (-3);
+ }
http_cb->cb = cb;
http_cb->cbarg = cbarg;
@@ -3911,6 +3920,10 @@ parse_authority(struct evhttp_uri *uri, char *s, char *eos)
EVUTIL_ASSERT(eos);
if (eos == s) {
uri->host = mm_strdup("");
+ if (uri->host == NULL) {
+ event_warn("%s: strdup", __func__);
+ return -1;
+ }
return 0;
}
@@ -3922,6 +3935,10 @@ parse_authority(struct evhttp_uri *uri, char *s, char *eos)
return -1;
*cp++ = '\0';
uri->userinfo = mm_strdup(s);
+ if (uri->userinfo == NULL) {
+ event_warn("%s: strdup", __func__);
+ return -1;
+ }
} else {
cp = s;
}
@@ -3949,6 +3966,10 @@ parse_authority(struct evhttp_uri *uri, char *s, char *eos)
return -1;
}
uri->host = mm_malloc(eos-cp+1);
+ if (uri->host == NULL) {
+ event_warn("%s: malloc", __func__);
+ return -1;
+ }
memcpy(uri->host, cp, eos-cp);
uri->host[eos-cp] = '\0';
return 0;
@@ -4039,7 +4060,10 @@ evhttp_uri_parse(const char *source_uri)
if (token && scheme_ok(readp,token)) {
*token = '\0';
uri->scheme = mm_strdup(readp);
-
+ if (uri->scheme == NULL) {
+ event_err(1, "%s: strdup", __func__);
+ goto err;
+ }
readp = token+1; /* eat : */
}
@@ -4096,11 +4120,25 @@ evhttp_uri_parse(const char *source_uri)
EVUTIL_ASSERT(path);
uri->path = mm_strdup(path);
+ if (uri->path == NULL) {
+ event_err(1, "%s: strdup", __func__);
+ goto err;
+ }
- if (query)
+ if (query) {
uri->query = mm_strdup(query);
- if (fragment)
+ if (uri->query == NULL) {
+ event_err(1, "%s: strdup", __func__);
+ goto err;
+ }
+ }
+ if (fragment) {
uri->fragment = mm_strdup(fragment);
+ if (uri->fragment == NULL) {
+ event_err(1, "%s: strdup", __func__);
+ goto err;
+ }
+ }
mm_free(readbuf);