From e5cac38521c17ac184235a687cd0639f3c7e85f2 Mon Sep 17 00:00:00 2001 From: Peter Keresztes Schmidt Date: Mon, 24 May 2021 00:44:15 +0200 Subject: [PATCH] Comms: Make sure sun_path is NUL-terminated MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When using strncpy the NUL-termination can go missing if the string to be copied is longer than the buffer. Make sure the last character in the buffer is NUL. If this really happens, the error (non-existing path due to truncation) will be caught during bind-ing. Fixes the following warning: /home/peterke/DEV/zoneminder/src/zm_comms.cpp: In member function ‘bool ZM::SockAddrUnix::resolve(const char*, const char*)’: /home/peterke/DEV/zoneminder/src/zm_comms.cpp:207:10: warning: ‘char* strncpy(char*, const char*, size_t)’ specified bound 108 equals destination size [-Wstringop-truncation] 207 | strncpy(mAddrUn.sun_path, path, sizeof(mAddrUn.sun_path)); | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --- src/zm_comms.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/zm_comms.cpp b/src/zm_comms.cpp index bef10164d..e3855bdea 100644 --- a/src/zm_comms.cpp +++ b/src/zm_comms.cpp @@ -205,6 +205,7 @@ bool ZM::SockAddrUnix::resolve(const char *path, const char *proto) { memset(&mAddrUn, 0, sizeof(mAddrUn)); strncpy(mAddrUn.sun_path, path, sizeof(mAddrUn.sun_path)); + mAddrUn.sun_path[sizeof(mAddrUn.sun_path) - 1] = '\0'; mAddrUn.sun_family = AF_UNIX; return true;