]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Update IPC sockets verification check
authorAmos Jeffries <squid3@treenet.co.nz>
Thu, 8 Jan 2015 23:41:52 +0000 (15:41 -0800)
committerAmos Jeffries <squid3@treenet.co.nz>
Thu, 8 Jan 2015 23:41:52 +0000 (15:41 -0800)
Coverity Scan gets confused by the code trick of using memset() on a
buffer then filling arbitrary string data into all but the final byte of
that buffer - thus implicitly null terminating.

Try an explicit null termination instead of memset(), this should make
Coverity a bit happier and is also faster than zero'ing the entire buf.

Coverity Issue 1258700

src/ipc.cc

index 240d5d622dafa70a8d724cc24b16b0a42d8b01fb..5a90a3aafcb48299d51ea50570d68d937365da32 100644 (file)
@@ -21,7 +21,9 @@
 #include "tools.h"
 
 static const char *hello_string = "hi there\n";
+#ifndef HELLO_BUF_SZ
 #define HELLO_BUF_SZ 32
+#endif
 static char hello_buf[HELLO_BUF_SZ];
 
 static int
@@ -244,12 +246,12 @@ ipcCreate(int type, const char *prog, const char *const args[], const char *name
                 return ipcCloseAllFD(prfd, pwfd, crfd, cwfd);
         }
 
-        memset(hello_buf, '\0', HELLO_BUF_SZ);
-
         if (type == IPC_UDP_SOCKET)
-            x = comm_udp_recv(prfd, hello_buf, HELLO_BUF_SZ - 1, 0);
+            x = comm_udp_recv(prfd, hello_buf, sizeof(hello_buf)-1, 0);
         else
-            x = read(prfd, hello_buf, HELLO_BUF_SZ - 1);
+            x = read(prfd, hello_buf, sizeof(hello_buf)-1);
+        if (x >= 0)
+            hello_buf[x+1] = '\0';
 
         if (x < 0) {
             debugs(54, DBG_CRITICAL, "ipcCreate: PARENT: hello read test failed");