]> granicus.if.org Git - libevent/commitdiff
Clean up some problems identified by Coverity.
authorHarlan Stenn <stenn@ntp.org>
Sat, 27 Aug 2011 09:48:11 +0000 (05:48 -0400)
committerNick Mathewson <nickm@torproject.org>
Sun, 28 Aug 2011 17:44:33 +0000 (13:44 -0400)
bufferevent_sock.c
evrpc.c
evutil.c
sample/dns-example.c
sample/http-server.c
test/bench_http.c

index 6aff91ea83d7b809f5e90cd0eee950dfb1cf995c..975b5b6cd309ceda8cd80a8a6bdb03819495113e 100644 (file)
@@ -113,8 +113,9 @@ bufferevent_socket_outbuf_cb(struct evbuffer *buf,
            !bufev_p->write_suspended) {
                /* Somebody added data to the buffer, and we would like to
                 * write, and we were not writing.  So, start writing. */
-               be_socket_add(&bufev->ev_write, &bufev->timeout_write);
-               /* XXXX handle failure from be_socket_add */
+               if (be_socket_add(&bufev->ev_write, &bufev->timeout_write) == -1) {
+                   // Should we log this?
+               }
        }
 }
 
diff --git a/evrpc.c b/evrpc.c
index e11892dcc07175cee690dec8bf9898b8a4014fa6..0c084a4a8e4681b8458414bd47baba911fad53c9 100644 (file)
--- a/evrpc.c
+++ b/evrpc.c
@@ -338,6 +338,7 @@ static void
 evrpc_request_cb_closure(void *arg, enum EVRPC_HOOK_RESULT hook_res)
 {
        struct evrpc_req_generic *rpc_state = arg;
+       EVUTIL_ASSERT(rpc_state);
        struct evrpc *rpc = rpc_state->rpc;
        struct evhttp_request *req = rpc_state->http_req;
 
@@ -399,8 +400,13 @@ evrpc_request_done_closure(void *, enum EVRPC_HOOK_RESULT);
 void
 evrpc_request_done(struct evrpc_req_generic *rpc_state)
 {
-       struct evhttp_request *req = rpc_state->http_req;
-       struct evrpc *rpc = rpc_state->rpc;
+       struct evhttp_request *req;
+       struct evrpc *rpc;
+
+       EVUTIL_ASSERT(rpc_state);
+
+       req = rpc_state->http_req;
+       rpc = rpc_state->rpc;
 
        if (rpc->reply_complete(rpc_state->reply) == -1) {
                /* the reply was not completely filled in.  error out */
@@ -466,6 +472,7 @@ static void
 evrpc_request_done_closure(void *arg, enum EVRPC_HOOK_RESULT hook_res)
 {
        struct evrpc_req_generic *rpc_state = arg;
+       EVUTIL_ASSERT(rpc_state);
        struct evhttp_request *req = rpc_state->http_req;
 
        if (hook_res == EVRPC_TERMINATE)
index adfcb6e56f5a9906dd95fca9db41cc1c9be19f84..f9d0c8b0fbfe55ff68746b59827789e0defd75ac 100644 (file)
--- a/evutil.c
+++ b/evutil.c
@@ -445,9 +445,9 @@ evutil_socket_connect(evutil_socket_t *fd_ptr, struct sockaddr *sa, int socklen)
        int made_fd = 0;
 
        if (*fd_ptr < 0) {
-               made_fd = 1;
                if ((*fd_ptr = socket(sa->sa_family, SOCK_STREAM, 0)) < 0)
                        goto err;
+               made_fd = 1;
                if (evutil_make_socket_nonblocking(*fd_ptr) < 0) {
                        goto err;
                }
index f2c1e020a0072ae76cda95ed5a215adb77102fb6..c5f377d39aa20c968ad349b0cfd0fa531afb5dee 100644 (file)
@@ -173,6 +173,10 @@ main(int c, char **v) {
                evutil_socket_t sock;
                struct sockaddr_in my_addr;
                sock = socket(PF_INET, SOCK_DGRAM, 0);
+               if (sock == -1) {
+                       perror("socket");
+                       exit(1);
+               }
                evutil_make_socket_nonblocking(sock);
                my_addr.sin_family = AF_INET;
                my_addr.sin_port = htons(10053);
index 75caa414e2bce4168ee3aa5f15470e52239c3293..cd6b27aff8b1f30b2618271b9ae986129526e08b 100644 (file)
@@ -133,7 +133,8 @@ dump_request_cb(struct evhttp_request *req, void *arg)
                int n;
                char cbuf[128];
                n = evbuffer_remove(buf, cbuf, sizeof(buf)-1);
-               fwrite(cbuf, 1, n, stdout);
+               if (n > 0)
+                   fwrite(cbuf, 1, n, stdout);
        }
        puts(">>>");
 
@@ -179,6 +180,8 @@ send_document_cb(struct evhttp_request *req, void *arg)
 
        /* We need to decode it, to see what path the user really wanted. */
        decoded_path = evhttp_uridecode(path, 0, NULL);
+       if (decoded_path == NULL)
+               goto err;
        /* Don't allow any ".."s in the path, to avoid exposing stuff outside
         * of the docroot.  This test is both overzealous and underzealous:
         * it forbids aceptable paths like "/this/one..here", but it doesn't
index dd3dde896056e22affa88bf2ee7b0f301c6b3690..9fdd5aab23803fd10163650d187766fd70c04a0e 100644 (file)
@@ -112,11 +112,20 @@ main(int argc, char **argv)
                }
 
                switch (c) {
+               char ** eptr;
                case 'p':
-                       port = atoi(argv[i+1]);
+                       port = (int)strtol(argv[i+1], eptr, 10);
+                       if (!(argv[i+1] && (**eptr == '\0'))) {
+                               fprintf(stderr, "Bad port\n");
+                               exit(1);
+                       }
                        break;
                case 'l':
-                       content_len = atol(argv[i+1]);
+                       content_len = (int)strtol(argv[i+1], eptr, 10);
+                       if (!(argv[i+1] && (**eptr == '\0'))) {
+                               fprintf(stderr, "Bad content length\n");
+                               exit(1);
+                       }
                        if (content_len == 0) {
                                fprintf(stderr, "Bad content length\n");
                                exit(1);