diff options
author | Mihai Moldovan <ionic@ionic.de> | 2017-12-30 03:31:20 +0100 |
---|---|---|
committer | Mihai Moldovan <ionic@ionic.de> | 2017-12-30 03:31:20 +0100 |
commit | e13e31f752c0b204f964ee1df272a6b31ce51189 (patch) | |
tree | d3bc2368895d03487b994fedff953ac457c4acc0 /nxcomp/src/Proxy.cpp | |
parent | 2d44051aad601e074790eaf482ef09090131ca5d (diff) | |
parent | 367bec59524ffc3d005ae8908c5edf42e9b01ca7 (diff) | |
download | nx-libs-e13e31f752c0b204f964ee1df272a6b31ce51189.tar.gz nx-libs-e13e31f752c0b204f964ee1df272a6b31ce51189.tar.bz2 nx-libs-e13e31f752c0b204f964ee1df272a6b31ce51189.zip |
Merge branch 'uli42-pr/fix_abstract' into 3.6.x
Attributes GH PR #615: https://github.com/ArcticaProject/nx-libs/pull/615
Fixes: ArcticaProject/nx-libs#612
Fixes: ArcticaProject/nx-libs#572
Diffstat (limited to 'nxcomp/src/Proxy.cpp')
-rw-r--r-- | nxcomp/src/Proxy.cpp | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/nxcomp/src/Proxy.cpp b/nxcomp/src/Proxy.cpp index 437296f60..7f72fae3f 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> @@ -6122,7 +6123,7 @@ int Proxy::handleNewSlaveConnection(int clientFd) int Proxy::handleNewGenericConnectionFromProxy(int channelId, T_channel_type type, ChannelEndPoint &endPoint, const char *label) { - char *unixPath, *host; + char *unixPath = NULL, *host = NULL; long port; if (endPoint.getUnixPath(&unixPath)) { @@ -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 " |