Unverified Commit e13e31f7 authored by Mihai Moldovan's avatar Mihai Moldovan

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
parents 2d44051a 367bec59
...@@ -212,16 +212,14 @@ int Auth::getCookie() ...@@ -212,16 +212,14 @@ int Auth::getCookie()
if (environment != NULL && *environment != '\0') if (environment != NULL && *environment != '\0')
{ {
strncpy(file_, environment, DEFAULT_STRING_LIMIT - 1); snprintf(file_, DEFAULT_STRING_LIMIT, "%s", environment);
} }
else else
{ {
snprintf(file_, DEFAULT_STRING_LIMIT - 1, "%s/.Xauthority", snprintf(file_, DEFAULT_STRING_LIMIT, "%s/.Xauthority",
control -> HomePath); control -> HomePath);
} }
*(file_ + DEFAULT_STRING_LIMIT - 1) = '\0';
#ifdef TEST #ifdef TEST
*logofs << "Auth: Using X authorization file '" << file_ *logofs << "Auth: Using X authorization file '" << file_
<< "'.\n" << logofs_flush; << "'.\n" << logofs_flush;
...@@ -242,18 +240,14 @@ int Auth::getCookie() ...@@ -242,18 +240,14 @@ int Auth::getCookie()
#if defined(__CYGWIN32__) #if defined(__CYGWIN32__)
snprintf(command, DEFAULT_STRING_LIMIT - 1, snprintf(command, DEFAULT_STRING_LIMIT,
"%s/bin/nxauth", control -> SystemPath); "%s/bin/nxauth", control -> SystemPath);
*(command + DEFAULT_STRING_LIMIT - 1) = '\0';
#elif defined(__APPLE__) #elif defined(__APPLE__)
snprintf(command, DEFAULT_STRING_LIMIT - 1, snprintf(command, DEFAULT_STRING_LIMIT,
"%s/nxauth", control -> SystemPath); "%s/nxauth", control -> SystemPath);
*(command + DEFAULT_STRING_LIMIT - 1) = '\0';
#else #else
strcpy(command, "xauth"); strcpy(command, "xauth");
......
...@@ -113,13 +113,19 @@ ChannelEndPoint::setSpec(const char *hostName, long port) { ...@@ -113,13 +113,19 @@ ChannelEndPoint::setSpec(const char *hostName, long port) {
bool bool
ChannelEndPoint::getSpec(char **socketUri) const { ChannelEndPoint::getSpec(char **socketUri) const {
if (socketUri) *socketUri = NULL; if (socketUri)
{
*socketUri = NULL;
}
else
{
return false;
}
char *unixPath = NULL; char *unixPath = NULL;
char *hostName = NULL; char *hostName = NULL;
long port = -1; long port = -1;
char *newSocketUri = NULL;
int length = -1; int length = -1;
if (getUnixPath(&unixPath)) if (getUnixPath(&unixPath))
...@@ -133,17 +139,21 @@ ChannelEndPoint::getSpec(char **socketUri) const { ...@@ -133,17 +139,21 @@ ChannelEndPoint::getSpec(char **socketUri) const {
if (length > 0) if (length > 0)
{ {
newSocketUri = static_cast<char *>(calloc(length + 1, sizeof(char))); char *newSocketUri = static_cast<char *>(calloc(length + 1, sizeof(char)));
if (isUnixSocket())
snprintf(newSocketUri, length+1, "unix:%s", unixPath); if (newSocketUri)
else {
snprintf(newSocketUri, length+1, "tcp:%s:%ld", hostName, port); if (isUnixSocket())
snprintf(newSocketUri, length+1, "unix:%s", unixPath);
else
snprintf(newSocketUri, length+1, "tcp:%s:%ld", hostName, port);
if (socketUri)
*socketUri = strdup(newSocketUri); *socketUri = strdup(newSocketUri);
SAFE_FREE(newSocketUri);
}
} }
SAFE_FREE(newSocketUri);
SAFE_FREE(unixPath); SAFE_FREE(unixPath);
SAFE_FREE(hostName); SAFE_FREE(hostName);
...@@ -170,8 +180,6 @@ ChannelEndPoint::setDefaultUnixPath(char *path) { ...@@ -170,8 +180,6 @@ ChannelEndPoint::setDefaultUnixPath(char *path) {
if (path && strlen(path)) if (path && strlen(path))
defaultUnixPath_ = strdup(path); defaultUnixPath_ = strdup(path);
else
defaultUnixPath_ = NULL;
isUnix_ = getUnixPath(); isUnix_ = getUnixPath();
} }
...@@ -199,7 +207,10 @@ ChannelEndPoint::getPort(long *port) const { ...@@ -199,7 +207,10 @@ ChannelEndPoint::getPort(long *port) const {
bool bool
ChannelEndPoint::getUnixPath(char **unixPath) const { ChannelEndPoint::getUnixPath(char **unixPath) const {
if (unixPath) *unixPath = NULL; if (unixPath)
*unixPath = NULL;
else
return false;
long p; long p;
char *path = NULL; char *path = NULL;
...@@ -219,8 +230,7 @@ ChannelEndPoint::getUnixPath(char **unixPath) const { ...@@ -219,8 +230,7 @@ ChannelEndPoint::getUnixPath(char **unixPath) const {
return false; return false;
} }
if (unixPath) *unixPath = strdup(path);
*unixPath = strdup(path);
return true; return true;
} }
...@@ -263,8 +273,10 @@ ChannelEndPoint::getTCPHostAndPort(char **host, long *port) const { ...@@ -263,8 +273,10 @@ ChannelEndPoint::getTCPHostAndPort(char **host, long *port) const {
char *h = NULL; char *h = NULL;
ssize_t h_len; ssize_t h_len;
if (host) *host = NULL; if (host)
if (port) *port = 0; *host = NULL;
if (port)
*port = 0;
if (getPort(&p)) { if (getPort(&p)) {
h_len = 0; h_len = 0;
......
...@@ -275,12 +275,14 @@ int NXTransDialog(const char *caption, const char *message, ...@@ -275,12 +275,14 @@ int NXTransDialog(const char *caption, const char *message,
#ifdef __APPLE__ #ifdef __APPLE__
// FIXME: missing length limitation!
strcat(newPath, "/Applications/NX Client for OSX.app/Contents/MacOS:"); strcat(newPath, "/Applications/NX Client for OSX.app/Contents/MacOS:");
#endif #endif
#ifdef __CYGWIN32__ #ifdef __CYGWIN32__
// FIXME: missing length limitation!
strcat(newPath, ".:"); strcat(newPath, ".:");
#endif #endif
...@@ -289,9 +291,8 @@ int NXTransDialog(const char *caption, const char *message, ...@@ -289,9 +291,8 @@ int NXTransDialog(const char *caption, const char *message,
char *oldPath = getenv("PATH"); char *oldPath = getenv("PATH");
strncpy(newPath + newLength, oldPath, DEFAULT_STRING_LIMIT - newLength - 1); // FIXME: check if strncat would be better here
snprintf(newPath + newLength, DEFAULT_STRING_LIMIT - newLength, "%s", oldPath);
newPath[DEFAULT_STRING_LIMIT - 1] = '\0';
#ifdef WARNING #ifdef WARNING
*logofs << "NXTransDialog: WARNING! Trying with path '" *logofs << "NXTransDialog: WARNING! Trying with path '"
...@@ -427,17 +428,13 @@ int NXTransClient(const char* display) ...@@ -427,17 +428,13 @@ int NXTransClient(const char* display)
#ifdef __sun #ifdef __sun
snprintf(newDisplay, DISPLAY_LENGTH_LIMIT - 1, "DISPLAY=%s", display); snprintf(newDisplay, DISPLAY_LENGTH_LIMIT, "DISPLAY=%s", display);
newDisplay[DISPLAY_LENGTH_LIMIT - 1] = '\0';
putenv(newDisplay); putenv(newDisplay);
#else #else
strncpy(newDisplay, display, DISPLAY_LENGTH_LIMIT - 1); snprintf(newDisplay, DISPLAY_LENGTH_LIMIT, "%s", display);
newDisplay[DISPLAY_LENGTH_LIMIT - 1] = '\0';
setenv("DISPLAY", newDisplay, 1); setenv("DISPLAY", newDisplay, 1);
...@@ -467,6 +464,7 @@ int NXTransClient(const char* display) ...@@ -467,6 +464,7 @@ int NXTransClient(const char* display)
if (i == 0) if (i == 0)
{ {
// FIXME: code dpulication: this whole block is duplicated in NXTransDialog
strcpy(command, "nxclient"); strcpy(command, "nxclient");
char newPath[DEFAULT_STRING_LIMIT]; char newPath[DEFAULT_STRING_LIMIT];
...@@ -489,7 +487,8 @@ int NXTransClient(const char* display) ...@@ -489,7 +487,8 @@ int NXTransClient(const char* display)
char *oldPath = getenv("PATH"); char *oldPath = getenv("PATH");
strncpy(newPath + newLength, oldPath, DEFAULT_STRING_LIMIT - newLength - 1); // FIXME: check if strncat would be better here
snprintf(newPath + newLength, DEFAULT_STRING_LIMIT - newLength, "%s", oldPath);
newPath[DEFAULT_STRING_LIMIT - 1] = '\0'; newPath[DEFAULT_STRING_LIMIT - 1] = '\0';
......
...@@ -70,6 +70,13 @@ EncodeBuffer::EncodeBuffer() ...@@ -70,6 +70,13 @@ EncodeBuffer::EncodeBuffer()
initialSize_ = ENCODE_BUFFER_DEFAULT_SIZE; initialSize_ = ENCODE_BUFFER_DEFAULT_SIZE;
thresholdSize_ = ENCODE_BUFFER_DEFAULT_SIZE << 1; thresholdSize_ = ENCODE_BUFFER_DEFAULT_SIZE << 1;
maximumSize_ = ENCODE_BUFFER_DEFAULT_SIZE << 4; maximumSize_ = ENCODE_BUFFER_DEFAULT_SIZE << 4;
#ifdef VALGRIND
memset(buffer_, '\0', size_);
#endif
} }
EncodeBuffer::~EncodeBuffer() EncodeBuffer::~EncodeBuffer()
...@@ -101,7 +108,15 @@ void EncodeBuffer::fullReset() ...@@ -101,7 +108,15 @@ void EncodeBuffer::fullReset()
size_ = initialSize_; size_ = initialSize_;
buffer_ = new unsigned char[size_ + ENCODE_BUFFER_PREFIX_SIZE + buffer_ = new unsigned char[size_ + ENCODE_BUFFER_PREFIX_SIZE +
ENCODE_BUFFER_POSTFIX_SIZE] + ENCODE_BUFFER_PREFIX_SIZE; ENCODE_BUFFER_POSTFIX_SIZE];
#ifdef VALGRIND
memset(buffer_, '\0', size_ + ENCODE_BUFFER_PREFIX_SIZE + ENCODE_BUFFER_POSTFIX_SIZE);
#endif
buffer_ += ENCODE_BUFFER_PREFIX_SIZE;
} }
end_ = buffer_ + size_; end_ = buffer_ + size_;
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <cstdio> #include <cstdio>
#include <unistd.h> #include <unistd.h>
#include <cstdlib> #include <cstdlib>
#include <cstddef>
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
...@@ -6122,7 +6123,7 @@ int Proxy::handleNewSlaveConnection(int clientFd) ...@@ -6122,7 +6123,7 @@ int Proxy::handleNewSlaveConnection(int clientFd)
int Proxy::handleNewGenericConnectionFromProxy(int channelId, T_channel_type type, int Proxy::handleNewGenericConnectionFromProxy(int channelId, T_channel_type type,
ChannelEndPoint &endPoint, const char *label) ChannelEndPoint &endPoint, const char *label)
{ {
char *unixPath, *host; char *unixPath = NULL, *host = NULL;
long port; long port;
if (endPoint.getUnixPath(&unixPath)) { if (endPoint.getUnixPath(&unixPath)) {
...@@ -6294,19 +6295,12 @@ int Proxy::handleNewGenericConnectionFromProxyUnix(int channelId, T_channel_type ...@@ -6294,19 +6295,12 @@ int Proxy::handleNewGenericConnectionFromProxyUnix(int channelId, T_channel_type
serverAddrUnix.sun_family = AF_UNIX; serverAddrUnix.sun_family = AF_UNIX;
#ifdef __linux__ // determine the maximum number of characters that fit into struct
const int serverAddrNameLength = 108; // sockaddr_un's sun_path member
#else std::size_t serverAddrNameLength =
/* POSIX/SUS does not specify a length. sizeof(struct sockaddr_un) - offsetof(struct sockaddr_un, sun_path);
* 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);
*(serverAddrUnix.sun_path + serverAddrNameLength - 1) = '\0'; snprintf(serverAddrUnix.sun_path, serverAddrNameLength, "%s", path);
#ifdef TEST #ifdef TEST
*logofs << "Proxy: Connecting to " << label << " server " *logofs << "Proxy: Connecting to " << label << " server "
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment