diff options
author | Nick Mathewson <nickm@torproject.org> | 2012-07-26 09:35:43 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2012-07-26 09:35:43 -0400 |
commit | 4f3732d75eb148f93efae797511213e92467f7a2 (patch) | |
tree | 0c3b5f931284a22df34a86f81528c637cb812ee3 | |
parent | f1ce15d936ea6f0b68ebc21cff169dfd1da2e1c1 (diff) | |
download | libevent-4f3732d75eb148f93efae797511213e92467f7a2.tar.gz |
Fix various check-after-dereference issues in unit tests: found by coverity
-rw-r--r-- | test/regress.c | 4 | ||||
-rw-r--r-- | test/regress_buffer.c | 11 | ||||
-rw-r--r-- | test/regress_dns.c | 14 | ||||
-rw-r--r-- | test/regress_et.c | 2 | ||||
-rw-r--r-- | test/regress_http.c | 8 | ||||
-rw-r--r-- | test/regress_rpc.c | 3 |
6 files changed, 35 insertions, 7 deletions
diff --git a/test/regress.c b/test/regress.c index 65921420..bd294845 100644 --- a/test/regress.c +++ b/test/regress.c @@ -2155,6 +2155,10 @@ test_event_pending(void *ptr) NULL); t = evtimer_new(data->base, timeout_cb, NULL); + tt_assert(r); + tt_assert(w); + tt_assert(t); + evutil_gettimeofday(&now, NULL); event_add(r, NULL); event_add(t, &tv); diff --git a/test/regress_buffer.c b/test/regress_buffer.c index 6a2b6fcc..99a8c0ea 100644 --- a/test/regress_buffer.c +++ b/test/regress_buffer.c @@ -1033,6 +1033,8 @@ test_evbuffer_find(void *ptr) unsigned int i; struct evbuffer * buf = evbuffer_new(); + tt_assert(buf); + /* make sure evbuffer_find doesn't match past the end of the buffer */ evbuffer_add(buf, (u_char*)test1, strlen(test1)); evbuffer_validate(buf); @@ -1074,6 +1076,8 @@ test_evbuffer_ptr_set(void *ptr) struct evbuffer_ptr pos; struct evbuffer_iovec v[1]; + tt_assert(buf); + /* create some chains */ evbuffer_reserve_space(buf, 5000, v, 1); v[0].iov_len = 5000; @@ -1121,6 +1125,9 @@ test_evbuffer_search(void *ptr) struct evbuffer *tmp = evbuffer_new(); struct evbuffer_ptr pos, end; + tt_assert(buf); + tt_assert(tmp); + /* set up our chains */ evbuffer_add_printf(tmp, "hello"); /* 5 chars */ evbuffer_add_buffer(buf, tmp); @@ -1200,6 +1207,10 @@ test_evbuffer_callbacks(void *ptr) struct evbuffer *buf_out2 = evbuffer_new(); struct evbuffer_cb_entry *cb1, *cb2; + tt_assert(buf); + tt_assert(buf_out1); + tt_assert(buf_out2); + cb1 = evbuffer_add_cb(buf, log_change_callback, buf_out1); cb2 = evbuffer_add_cb(buf, log_change_callback, buf_out2); diff --git a/test/regress_dns.c b/test/regress_dns.c index b34fb96c..557a63d6 100644 --- a/test/regress_dns.c +++ b/test/regress_dns.c @@ -1066,6 +1066,7 @@ test_bufferevent_connect_hostname(void *arg) &n_accept, LEV_OPT_REUSEABLE|LEV_OPT_CLOSE_ON_EXEC, -1, (struct sockaddr *)&sin, sizeof(sin)); + tt_assert(listener); listener_port = regress_get_socket_port( evconnlistener_get_fd(listener)); @@ -1211,6 +1212,7 @@ test_getaddrinfo_async(void *arg) int n_dns_questions = 0; struct evdns_base *dns_base = evdns_base_new(data->base, 0); + tt_assert(dns_base); /* for localhost */ evdns_base_load_hosts(dns_base, NULL); @@ -1705,6 +1707,7 @@ testleak_cleanup(const struct testcase_t *testcase, void *env_) { int ok = 0; struct testleak_env_t *env = env_; + tt_assert(env); #ifdef _EVENT_DISABLE_DEBUG_MODE tt_int_op(allocated_chunks, ==, 0); #else @@ -1713,12 +1716,13 @@ testleak_cleanup(const struct testcase_t *testcase, void *env_) #endif ok = 1; end: - if (env->dns_base) - evdns_base_free(env->dns_base, 0); - if (env->base) - event_base_free(env->base); - if (env) + if (env) { + if (env->dns_base) + evdns_base_free(env->dns_base, 0); + if (env->base) + event_base_free(env->base); free(env); + } return ok; } diff --git a/test/regress_et.c b/test/regress_et.c index dee7b936..54ee9326 100644 --- a/test/regress_et.c +++ b/test/regress_et.c @@ -173,7 +173,9 @@ test_edgetriggered_mix_error(void *data_) /* try mixing edge-triggered and level-triggered to make sure it fails*/ ev_et = event_new(base, data->pair[0], EV_READ|EV_ET, read_cb, ev_et); + tt_assert(ev_et); ev_lt = event_new(base, data->pair[0], EV_READ, read_cb, ev_lt); + tt_assert(ev_lt); /* Add edge-triggered, then level-triggered. Get an error. */ tt_int_op(0, ==, event_add(ev_et, NULL)); diff --git a/test/regress_http.c b/test/regress_http.c index f30b2e36..a8b21ce2 100644 --- a/test/regress_http.c +++ b/test/regress_http.c @@ -3213,26 +3213,30 @@ static void http_primitives(void *ptr) { char *escaped = NULL; - struct evhttp *http; + struct evhttp *http = NULL; escaped = evhttp_htmlescape("<script>"); + tt_assert(escaped); tt_str_op(escaped, ==, "<script>"); free(escaped); escaped = evhttp_htmlescape("\"\'&"); + tt_assert(escaped); tt_str_op(escaped, ==, ""'&"); http = evhttp_new(NULL); + tt_assert(http); tt_int_op(evhttp_set_cb(http, "/test", http_basic_cb, NULL), ==, 0); tt_int_op(evhttp_set_cb(http, "/test", http_basic_cb, NULL), ==, -1); tt_int_op(evhttp_del_cb(http, "/test"), ==, 0); tt_int_op(evhttp_del_cb(http, "/test"), ==, -1); tt_int_op(evhttp_set_cb(http, "/test", http_basic_cb, NULL), ==, 0); - evhttp_free(http); end: if (escaped) free(escaped); + if (http) + evhttp_free(http); } static void diff --git a/test/regress_rpc.c b/test/regress_rpc.c index 922fdc10..e03adcdf 100644 --- a/test/regress_rpc.c +++ b/test/regress_rpc.c @@ -734,6 +734,9 @@ rpc_test(void) int i; msg = msg_new(); + + tt_assert(msg); + EVTAG_ASSIGN(msg, from_name, "niels"); EVTAG_ASSIGN(msg, to_name, "phoenix"); |