diff options
author | Ulrich Sibiller <uli42@gmx.de> | 2017-12-27 14:53:58 +0100 |
---|---|---|
committer | Ulrich Sibiller <uli42@gmx.de> | 2017-12-29 02:31:26 +0100 |
commit | 6198e0376f9ce8130af3294fa284659f0055610d (patch) | |
tree | d49206bacca3e9ec4f3d70c0b0f204cf211c7ed2 /nxcomp/src/Proxy.cpp | |
parent | 2367fc714843fa0c19778e5a8e100c5f116255ee (diff) | |
download | nx-libs-6198e0376f9ce8130af3294fa284659f0055610d.tar.gz nx-libs-6198e0376f9ce8130af3294fa284659f0055610d.tar.bz2 nx-libs-6198e0376f9ce8130af3294fa284659f0055610d.zip |
nxcomp: implement correct length handling for unix socket structs
(partially) fixes ArcticaProject/nx-libs#612
Diffstat (limited to 'nxcomp/src/Proxy.cpp')
-rw-r--r-- | nxcomp/src/Proxy.cpp | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/nxcomp/src/Proxy.cpp b/nxcomp/src/Proxy.cpp index 437296f60..963ae3d75 100644 --- a/nxcomp/src/Proxy.cpp +++ b/nxcomp/src/Proxy.cpp @@ -30,6 +30,7 @@ #include <cstdio> #include <unistd.h> #include <cstdlib> +#include <cstddef> #include <string.h> #include <sys/types.h> #include <sys/stat.h> @@ -6294,19 +6295,12 @@ int Proxy::handleNewGenericConnectionFromProxyUnix(int channelId, T_channel_type serverAddrUnix.sun_family = AF_UNIX; - #ifdef __linux__ - const int serverAddrNameLength = 108; - #else - /* POSIX/SUS does not specify a length. - * BSD derivatives generally support 104 bytes, other systems may be more constrained. - * If you happen to run into such systems, extend this section with the appropriate limit. - */ - const int serverAddrNameLength = 104; - #endif - - strncpy(serverAddrUnix.sun_path, path, serverAddrNameLength); + // determine the maximum number of characters that fit into struct + // sockaddr_un's sun_path member + std::size_t serverAddrNameLength = + sizeof(struct sockaddr_un) - offsetof(struct sockaddr_un, sun_path); - *(serverAddrUnix.sun_path + serverAddrNameLength - 1) = '\0'; + snprintf(serverAddrUnix.sun_path, serverAddrNameLength, "%s", path); #ifdef TEST *logofs << "Proxy: Connecting to " << label << " server " |