Comms: Make sure sun_path is NUL-terminated
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)); | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This commit is contained in:
parent
93abbdf964
commit
e5cac38521
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue