]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
Final clang static analysis warning release-1.7.1-rc1
authorWillem Toorop <willem@nlnetlabs.nl>
Thu, 18 Jul 2019 19:00:59 +0000 (15:00 -0400)
committerWillem Toorop <willem@nlnetlabs.nl>
Thu, 18 Jul 2019 19:00:59 +0000 (15:00 -0400)
examples/ldns-testns.c

index 3a7dbae7f0e3fa8c7a293e2466d5d49b80d56573..b5d6dd47953fecb525b41322514aee3f116a0fb7 100644 (file)
@@ -273,7 +273,7 @@ handle_udp(int udp_sock, struct entry* entries, int *count)
                &userdata, do_verbose?logfile:0);
 }
 
-static void
+static int
 read_n_bytes(int sock, uint8_t* buf, size_t sz)
 {
        size_t count = 0;
@@ -281,14 +281,14 @@ read_n_bytes(int sock, uint8_t* buf, size_t sz)
                ssize_t nb = recv(sock, (void*)(buf+count), sz-count, 0);
                if(nb < 0) {
                        log_msg("recv(): %s\n", strerror(errno));
-                       return;
+                       return -1;
                } else if(nb == 0) {
                        log_msg("recv: remote end closed the channel\n");
-                       memset(buf+count, 0, sz-count);
-                       return;
+                       return sz-count;
                }
                count += nb;
        }
+       return 0;
 }
 
 static void
@@ -338,7 +338,8 @@ handle_tcp(int tcp_sock, struct entry* entries, int *count)
        userdata.s = s;
 
        /* tcp recv */
-       read_n_bytes(s, (uint8_t*)&tcplen, sizeof(tcplen));
+       if (read_n_bytes(s, (uint8_t*)&tcplen, sizeof(tcplen)))
+               return;
        tcplen = ntohs(tcplen);
        if(tcplen >= INBUF_SIZE) {
                log_msg("query %d bytes too large, buffer %d bytes.\n",
@@ -350,7 +351,8 @@ handle_tcp(int tcp_sock, struct entry* entries, int *count)
 #endif
                return;
        }
-       read_n_bytes(s, inbuf, tcplen);
+       if (read_n_bytes(s, inbuf, tcplen))
+               return;
 
        handle_query(inbuf, (ssize_t) tcplen, entries, count, transport_tcp, 
                send_tcp, &userdata, do_verbose?logfile:0);