summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiels Provos <provos@gmail.com>2006-11-16 08:49:26 +0000
committerNiels Provos <provos@gmail.com>2006-11-16 08:49:26 +0000
commit44bd5ab4e03a7fd943520243dd07bc3e6fdba249 (patch)
tree6fdc4c475079aacaab03e6ca90b5c0826006eb07
parent9d9d60b1ff0b588ee20b1b7a4f73ea409fad232d (diff)
downloadlibevent-44bd5ab4e03a7fd943520243dd07bc3e6fdba249.tar.gz
prefix was missing /; malformed request caused server to crash
svn:r256
-rw-r--r--evhttp.h1
-rw-r--r--evrpc-internal.h2
-rw-r--r--evrpc.c4
-rw-r--r--http.c22
4 files changed, 22 insertions, 7 deletions
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;