]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- Fix warnings reported by the gcc analyzer.
authorW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Wed, 23 Jun 2021 16:02:02 +0000 (18:02 +0200)
committerW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Wed, 23 Jun 2021 16:02:02 +0000 (18:02 +0200)
dnstap/unbound-dnstap-socket.c
doc/Changelog
libunbound/libworker.c
libunbound/python/libunbound.i
testcode/delayer.c
testcode/dohclient.c
testcode/fake_event.c
testcode/streamtcp.c

index 9eaf01243e1b835efc53a947af0f71cd1b5d3d9f..17c29e9718da6cb42b8567fbdba7829b0dce8b19 100644 (file)
@@ -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;
index 9ac461e5aaaee140eee3ba4711b99b094d12336e..84b85a4e9ea1dc925f0a83cd80995b99f29c58eb 100644 (file)
@@ -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.
index 4733eb4644b04becbb82030fee32378e44a7f076..8a9ca94194807f4c1bc0b50d3d68291d3bcec567 100644 (file)
@@ -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; i<data->count; 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; j<i; j++) {
+                               free(res->data[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) {
index ab244a6fb01fac91b718f8fd5d724c317fddbd25..763879e80869a057a200a7a6f49d21774c4134d0 100644 (file)
@@ -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;
    
index 54175dbe3ecc7a4f9d509a282d1f214caa3a476f..0c8f2a45d3b2b86fd60d53845b3f9efcaedfc500 100644 (file)
@@ -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;
 }
 
index 0dc039f263c12193f21e76f6cd355d14fa331633..93d84a83550d7366304ed77d887ec4c12204037d 100644 (file)
@@ -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);
index 125355f051a009e19d8227627990351b860f9186..901880ce630bb6d1757ab9fdc79a2565b227ddfc 100644 (file)
@@ -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 */
index ffdddbe9db48380805af1cbef8d550f56758a471..3fbb792e5100888d2704e71eec89760a9119ad6e 100644 (file)
@@ -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 */