]> granicus.if.org Git - libevent/commitdiff
evrpc: avoid NULL dereference on request is not EVHTTP_REQ_POST
authorAzat Khuzhin <a3at.mail@gmail.com>
Thu, 13 Sep 2018 23:24:44 +0000 (02:24 +0300)
committerAzat Khuzhin <azat@libevent.org>
Sat, 2 Feb 2019 12:17:59 +0000 (15:17 +0300)
Fixes: #660
(cherry picked from commit 8483c5351abdd18766232de8431290165717bd57)

evrpc.c
test/regress_rpc.c

diff --git a/evrpc.c b/evrpc.c
index 2443ab27937adfbeb8b750cdf960b56d4db7dba8..68fa1b90f3315cc95c6018171153cfc45a66e8fc 100644 (file)
--- a/evrpc.c
+++ b/evrpc.c
@@ -329,7 +329,8 @@ evrpc_request_cb(struct evhttp_request *req, void *arg)
        return;
 
 error:
-       evrpc_reqstate_free_(rpc_state);
+       if (rpc_state)
+               evrpc_reqstate_free_(rpc_state);
        evhttp_send_error(req, HTTP_SERVUNAVAIL, NULL);
        return;
 }
index 2cb2bcd9bca910b397b140df5655c5947f319c55..87a7efa12fc3b25e1f99b92f96ae8efc57870bf6 100644 (file)
@@ -879,6 +879,53 @@ end:
                evbuffer_free(tmp);
 }
 
+static void
+rpc_invalid_type(void)
+{
+       ev_uint16_t port;
+       struct evhttp *http = NULL;
+       struct evrpc_base *base = NULL;
+       struct evhttp_connection *evcon = NULL;
+       struct evhttp_request *req = NULL;
+
+       rpc_setup(&http, &port, &base);
+
+       evcon = evhttp_connection_new("127.0.0.1", port);
+       tt_assert(evcon);
+
+       /*
+        * At this point, we want to schedule an HTTP POST request
+        * server using our make request method.
+        */
+
+       req = evhttp_request_new(rpc_postrequest_failure, NULL);
+       tt_assert(req);
+
+       /* Add the information that we care about */
+       evhttp_add_header(req->output_headers, "Host", "somehost");
+       evbuffer_add_printf(req->output_buffer, "Some Nonsense");
+
+       if (evhttp_make_request(evcon, req,
+               EVHTTP_REQ_GET,
+               "/.rpc.Message") == -1) {
+               tt_abort();
+       }
+
+       test_ok = 0;
+
+       event_dispatch();
+
+       evhttp_connection_free(evcon);
+
+       rpc_teardown(base);
+
+       tt_assert(test_ok == 1);
+
+end:
+       evhttp_free(http);
+}
+
+
 #define RPC_LEGACY(name)                                               \
        { #name, run_legacy_test_fn, TT_FORK|TT_NEED_BASE|TT_LEGACY,    \
                    &legacy_setup,                                      \
@@ -897,6 +944,7 @@ struct testcase_t rpc_testcases[] = {
        RPC_LEGACY(basic_client),
        RPC_LEGACY(basic_queued_client),
        RPC_LEGACY(basic_client_with_pause),
+       RPC_LEGACY(invalid_type),
        RPC_LEGACY(client_timeout),
        RPC_LEGACY(test),