From: Willem Toorop Date: Thu, 18 Jul 2019 19:00:59 +0000 (-0400) Subject: Final clang static analysis warning X-Git-Tag: release-1.7.1-rc1^0 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=82192e3f017c427cc5db460d32b38e30370fd27d;p=thirdparty%2Fldns.git Final clang static analysis warning --- diff --git a/examples/ldns-testns.c b/examples/ldns-testns.c index 3a7dbae7..b5d6dd47 100644 --- a/examples/ldns-testns.c +++ b/examples/ldns-testns.c @@ -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);