From: Amos Jeffries Date: Thu, 8 Jan 2015 23:41:52 +0000 (-0800) Subject: Update IPC sockets verification check X-Git-Tag: merge-candidate-3-v1~360 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9ad18ba87ceaa92c3054405d860161385829178c;p=thirdparty%2Fsquid.git Update IPC sockets verification check 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 --- diff --git a/src/ipc.cc b/src/ipc.cc index 240d5d622d..5a90a3aafc 100644 --- a/src/ipc.cc +++ b/src/ipc.cc @@ -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");