From: Niels Provos Date: Thu, 16 Nov 2006 08:49:26 +0000 (+0000) Subject: prefix was missing /; malformed request caused server to crash X-Git-Tag: release-2.0.1-alpha~703 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=44bd5ab4e03a7fd943520243dd07bc3e6fdba249;p=libevent prefix was missing /; malformed request caused server to crash svn:r256 --- diff --git a/evhttp.h b/evhttp.h index ed74d71d..e2cec260 100644 --- a/evhttp.h +++ b/evhttp.h @@ -52,6 +52,7 @@ typedef unsigned char u_char; #define HTTP_OK 200 #define HTTP_MOVEPERM 301 #define HTTP_MOVETEMP 302 +#define HTTP_BADREQUEST 400 #define HTTP_NOTFOUND 404 #define HTTP_SERVUNAVAIL 503 diff --git a/evrpc-internal.h b/evrpc-internal.h index b5c4eaf8..4a27a364 100644 --- a/evrpc-internal.h +++ b/evrpc-internal.h @@ -29,7 +29,7 @@ struct evrpc; -#define EVRPC_URI_PREFIX ".rpc." +#define EVRPC_URI_PREFIX "/.rpc." struct evrpc_base { /* the HTTP server under which we register our RPC calls */ diff --git a/evrpc.c b/evrpc.c index 7def2cfe..4e9ba87d 100644 --- a/evrpc.c +++ b/evrpc.c @@ -165,10 +165,10 @@ error: void evrpc_reqstate_free(struct evrpc_req_generic* rpc_state) { - struct evrpc *rpc = rpc_state->rpc; - /* clean up all memory */ if (rpc_state != NULL) { + struct evrpc *rpc = rpc_state->rpc; + if (rpc_state->request != NULL) rpc->request_free(rpc_state); if (rpc_state->reply != NULL) diff --git a/http.c b/http.c index 1e350220..dd3ea5db 100644 --- a/http.c +++ b/http.c @@ -324,14 +324,23 @@ evhttp_connection_fail(struct evhttp_connection *evcon) struct evhttp_request* req = TAILQ_FIRST(&evcon->requests); assert(req != NULL); - /* reset the connection */ - evhttp_connection_reset(evcon); - if (req->cb != NULL) { - /* xxx: maybe we need to pass the request here? */ + /* + * we are passing the request object if we have an incoming + * request that somehow needs to be answered. we need to + * wait for the answer to travel over the wire before we can + * kill the connection. + */ + if (evcon->flags & EVHTTP_CON_INCOMING) { + (*req->cb)(req, req->cb_arg); + return; + } (*req->cb)(NULL, req->cb_arg); } + /* reset the connection */ + evhttp_connection_reset(evcon); + TAILQ_REMOVE(&evcon->requests, req, next); evhttp_request_free(req); @@ -1237,6 +1246,11 @@ evhttp_handle_request(struct evhttp_request *req, void *arg) struct evhttp *http = arg; struct evhttp_cb *cb; + if (req->uri == NULL) { + evhttp_send_error(req, HTTP_BADREQUEST, "Bad Request"); + return; + } + /* Test for different URLs */ TAILQ_FOREACH(cb, &http->callbacks, next) { int res;