From: W.C.A. Wijngaards Date: Wed, 23 Jun 2021 16:02:02 +0000 (+0200) Subject: - Fix warnings reported by the gcc analyzer. X-Git-Tag: release-1.13.2rc1~139 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d3b2bc501dae558d186e7cd6aebb9bc4a7d1f75d;p=thirdparty%2Funbound.git - Fix warnings reported by the gcc analyzer. --- diff --git a/dnstap/unbound-dnstap-socket.c b/dnstap/unbound-dnstap-socket.c index 9eaf01243..17c29e971 100644 --- a/dnstap/unbound-dnstap-socket.c +++ b/dnstap/unbound-dnstap-socket.c @@ -1012,6 +1012,7 @@ void dtio_tap_callback(int fd, short ATTR_UNUSED(bits), void* arg) if(verbosity) log_info("bidirectional stream"); if(!reply_with_accept(data)) { tap_data_free(data); + return; } } else if(data->len >= 4 && sldns_read_uint32(data->frame) == FSTRM_CONTROL_FRAME_STOP && data->is_bidirectional) { @@ -1166,8 +1167,12 @@ int sig_quit = 0; /** signal handler for user quit */ static RETSIGTYPE main_sigh(int sig) { - if(!sig_quit) - fprintf(stderr, "exit on signal %d\n", sig); + if(!sig_quit) { + char str[] = "exit on signal \n"; + str[15] = '0' + (sig/10)%10; + str[16] = '0' + sig%10; + write(STDERR_FILENO, str, strlen(str)); + } if(sig_base) { ub_event_base_loopexit(sig_base); sig_base = NULL; diff --git a/doc/Changelog b/doc/Changelog index 9ac461e5a..84b85a4e9 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,5 +1,6 @@ 23 June 2021: Wouter - Fix #503: DNS over HTTPS response truncated. + - Fix warnings reported by the gcc analyzer. 21 June 2021: George - Fix #495: Documentation or implementation of "verbosity" option. diff --git a/libunbound/libworker.c b/libunbound/libworker.c index 4733eb464..8a9ca9419 100644 --- a/libunbound/libworker.c +++ b/libunbound/libworker.c @@ -456,8 +456,15 @@ fill_res(struct ub_result* res, struct ub_packed_rrset_key* answer, if(rep->rrset_count != 0) res->ttl = (int)rep->ttl; res->data = (char**)calloc(1, sizeof(char*)); + if(!res->data) + return 0; /* out of memory */ res->len = (int*)calloc(1, sizeof(int)); - return (res->data && res->len); + if(!res->len) { + free(res->data); + res->data = NULL; + return 0; /* out of memory */ + } + return 1; } data = (struct packed_rrset_data*)answer->entry.data; if(query_dname_compare(rq->qname, answer->rk.dname) != 0) { @@ -465,15 +472,30 @@ fill_res(struct ub_result* res, struct ub_packed_rrset_key* answer, return 0; /* out of memory */ } else res->canonname = NULL; res->data = (char**)calloc(data->count+1, sizeof(char*)); + if(!res->data) + return 0; /* out of memory */ res->len = (int*)calloc(data->count+1, sizeof(int)); - if(!res->data || !res->len) + if(!res->len) { + free(res->data); + res->data = NULL; return 0; /* out of memory */ + } for(i=0; icount; i++) { /* remove rdlength from rdata */ res->len[i] = (int)(data->rr_len[i] - 2); res->data[i] = memdup(data->rr_data[i]+2, (size_t)res->len[i]); - if(!res->data[i]) + if(!res->data[i]) { + size_t j; + for(j=0; jdata[j]); + res->data[j] = NULL; + } + free(res->data); + res->data = NULL; + free(res->len); + res->len = NULL; return 0; /* out of memory */ + } } /* ttl for positive answers, from CNAME and answer RRs */ if(data->count != 0) { diff --git a/libunbound/python/libunbound.i b/libunbound/python/libunbound.i index ab244a6fb..763879e80 100644 --- a/libunbound/python/libunbound.i +++ b/libunbound/python/libunbound.i @@ -936,6 +936,8 @@ int _ub_resolve_async(struct ub_ctx* ctx, char* name, int rrtype, int rrclass, v int r; struct cb_data* id; id = (struct cb_data*) malloc(sizeof(struct cb_data)); + if(!id) + return -2; /* UB_NOMEM */ id->data = mydata; id->func = pyfunc; diff --git a/testcode/delayer.c b/testcode/delayer.c index 54175dbe3..0c8f2a45d 100644 --- a/testcode/delayer.c +++ b/testcode/delayer.c @@ -347,7 +347,10 @@ static volatile int do_quit = 0; /** signal handler for user quit */ static RETSIGTYPE delayer_sigh(int sig) { - printf("exit on signal %d\n", sig); + char str[] = "exit on signal \n"; + str[15] = '0' + (sig/10)%10; + str[16] = '0' + sig%10; + write(STDOUT_FILENO, str, strlen(str)); do_quit = 1; } diff --git a/testcode/dohclient.c b/testcode/dohclient.c index 0dc039f26..93d84a835 100644 --- a/testcode/dohclient.c +++ b/testcode/dohclient.c @@ -423,6 +423,7 @@ http2_session_create() if(nghttp2_session_callbacks_new(&callbacks) == NGHTTP2_ERR_NOMEM) { log_err("failed to initialize nghttp2 callback"); + free(h2_session); return NULL; } nghttp2_session_callbacks_set_recv_callback(callbacks, http2_recv_cb); diff --git a/testcode/fake_event.c b/testcode/fake_event.c index 125355f05..901880ce6 100644 --- a/testcode/fake_event.c +++ b/testcode/fake_event.c @@ -451,6 +451,8 @@ fake_front_query(struct replay_runtime* runtime, struct replay_moment *todo) struct comm_reply repinfo; memset(&repinfo, 0, sizeof(repinfo)); repinfo.c = (struct comm_point*)calloc(1, sizeof(struct comm_point)); + if(!repinfo.c) + fatal_exit("out of memory in fake_front_query"); repinfo.addrlen = (socklen_t)sizeof(struct sockaddr_in); if(todo->addrlen != 0) { repinfo.addrlen = todo->addrlen; @@ -909,6 +911,8 @@ comm_base_create(int ATTR_UNUSED(sigs)) /* we return the runtime structure instead. */ struct replay_runtime* runtime = (struct replay_runtime*) calloc(1, sizeof(struct replay_runtime)); + if(!runtime) + fatal_exit("out of memory in fake_event.c:comm_base_create"); runtime->scenario = saved_scenario; runtime->vars = macro_store_create(); if(!runtime->vars) fatal_exit("out of memory"); @@ -1534,6 +1538,8 @@ struct comm_timer* comm_timer_create(struct comm_base* base, { struct replay_runtime* runtime = (struct replay_runtime*)base; struct fake_timer* t = (struct fake_timer*)calloc(1, sizeof(*t)); + if(!t) + fatal_exit("out of memory in fake_event.c:comm_timer_create"); t->cb = cb; t->cb_arg = cb_arg; fptr_ok(fptr_whitelist_comm_timer(t->cb)); /* check in advance */ diff --git a/testcode/streamtcp.c b/testcode/streamtcp.c index ffdddbe9d..3fbb792e5 100644 --- a/testcode/streamtcp.c +++ b/testcode/streamtcp.c @@ -397,11 +397,15 @@ send_em(const char* svr, int udp, int usessl, int noanswer, int onarrival, /** SIGPIPE handler */ static RETSIGTYPE sigh(int sig) { + char str[] = "Got unhandled signal \n"; if(sig == SIGPIPE) { - printf("got SIGPIPE, remote connection gone\n"); + char* strpipe = "got SIGPIPE, remote connection gone\n"; + write(STDOUT_FILENO, strpipe, strlen(strpipe)); exit(1); } - printf("Got unhandled signal %d\n", sig); + str[21] = '0' + (sig/10)%10; + str[22] = '0' + sig%10; + write(STDOUT_FILENO, str, strlen(str)); exit(1); } #endif /* SIGPIPE */