]> granicus.if.org Git - libevent/commitdiff
prefix was missing /; malformed request caused server to crash
authorNiels Provos <provos@gmail.com>
Thu, 16 Nov 2006 08:49:26 +0000 (08:49 +0000)
committerNiels Provos <provos@gmail.com>
Thu, 16 Nov 2006 08:49:26 +0000 (08:49 +0000)
svn:r256

evhttp.h
evrpc-internal.h
evrpc.c
http.c

index ed74d71d27eaba69f8a279f7e81eab075f70ba8d..e2cec260b01013babb0c05eda4305526621a3814 100644 (file)
--- 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
 
index b5c4eaf82c000c597d5b393cdffbf9b87d2830a8..4a27a364f8aab81c7c70a0ed49c9c2d9e3160f7c 100644 (file)
@@ -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 7def2cfea23f656694dccf3f146ff7511ec20d65..4e9ba87d36373152c04d8a308fff9ca7278b71b7 100644 (file)
--- 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 1e3502208891a7884c4e9a5e399368bd8c75e5e6..dd3ea5db418021ef7d45b614c129a64e73c53834 100644 (file)
--- 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;