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()
if (environment != NULL && *environment != '\0')
{
strncpy(file_, environment, DEFAULT_STRING_LIMIT - 1);
snprintf(file_, DEFAULT_STRING_LIMIT, "%s", environment);
}
else
{
snprintf(file_, DEFAULT_STRING_LIMIT - 1, "%s/.Xauthority",
snprintf(file_, DEFAULT_STRING_LIMIT, "%s/.Xauthority",
control -> HomePath);
}
*(file_ + DEFAULT_STRING_LIMIT - 1) = '\0';
#ifdef TEST
*logofs << "Auth: Using X authorization file '" << file_
<< "'.\n" << logofs_flush;
......@@ -242,18 +240,14 @@ int Auth::getCookie()
#if defined(__CYGWIN32__)
snprintf(command, DEFAULT_STRING_LIMIT - 1,
snprintf(command, DEFAULT_STRING_LIMIT,
"%s/bin/nxauth", control -> SystemPath);
*(command + DEFAULT_STRING_LIMIT - 1) = '\0';
#elif defined(__APPLE__)
snprintf(command, DEFAULT_STRING_LIMIT - 1,
snprintf(command, DEFAULT_STRING_LIMIT,
"%s/nxauth", control -> SystemPath);
*(command + DEFAULT_STRING_LIMIT - 1) = '\0';
#else
strcpy(command, "xauth");
......
......@@ -113,13 +113,19 @@ ChannelEndPoint::setSpec(const char *hostName, long port) {
bool
ChannelEndPoint::getSpec(char **socketUri) const {
if (socketUri) *socketUri = NULL;
if (socketUri)
{
*socketUri = NULL;
}
else
{
return false;
}
char *unixPath = NULL;
char *hostName = NULL;
long port = -1;
char *newSocketUri = NULL;
int length = -1;
if (getUnixPath(&unixPath))
......@@ -133,17 +139,21 @@ ChannelEndPoint::getSpec(char **socketUri) const {
if (length > 0)
{
newSocketUri = static_cast<char *>(calloc(length + 1, sizeof(char)));
char *newSocketUri = static_cast<char *>(calloc(length + 1, sizeof(char)));
if (newSocketUri)
{
if (isUnixSocket())
snprintf(newSocketUri, length+1, "unix:%s", unixPath);
else
snprintf(newSocketUri, length+1, "tcp:%s:%ld", hostName, port);
if (socketUri)
*socketUri = strdup(newSocketUri);
}
SAFE_FREE(newSocketUri);
}
}
SAFE_FREE(unixPath);
SAFE_FREE(hostName);
......@@ -170,8 +180,6 @@ ChannelEndPoint::setDefaultUnixPath(char *path) {
if (path && strlen(path))
defaultUnixPath_ = strdup(path);
else
defaultUnixPath_ = NULL;
isUnix_ = getUnixPath();
}
......@@ -199,7 +207,10 @@ ChannelEndPoint::getPort(long *port) const {
bool
ChannelEndPoint::getUnixPath(char **unixPath) const {
if (unixPath) *unixPath = NULL;
if (unixPath)
*unixPath = NULL;
else
return false;
long p;
char *path = NULL;
......@@ -219,7 +230,6 @@ ChannelEndPoint::getUnixPath(char **unixPath) const {
return false;
}
if (unixPath)
*unixPath = strdup(path);
return true;
......@@ -263,8 +273,10 @@ ChannelEndPoint::getTCPHostAndPort(char **host, long *port) const {
char *h = NULL;
ssize_t h_len;
if (host) *host = NULL;
if (port) *port = 0;
if (host)
*host = NULL;
if (port)
*port = 0;
if (getPort(&p)) {
h_len = 0;
......
......@@ -275,12 +275,14 @@ int NXTransDialog(const char *caption, const char *message,
#ifdef __APPLE__
// FIXME: missing length limitation!
strcat(newPath, "/Applications/NX Client for OSX.app/Contents/MacOS:");
#endif
#ifdef __CYGWIN32__
// FIXME: missing length limitation!
strcat(newPath, ".:");
#endif
......@@ -289,9 +291,8 @@ int NXTransDialog(const char *caption, const char *message,
char *oldPath = getenv("PATH");
strncpy(newPath + newLength, oldPath, DEFAULT_STRING_LIMIT - newLength - 1);
newPath[DEFAULT_STRING_LIMIT - 1] = '\0';
// FIXME: check if strncat would be better here
snprintf(newPath + newLength, DEFAULT_STRING_LIMIT - newLength, "%s", oldPath);
#ifdef WARNING
*logofs << "NXTransDialog: WARNING! Trying with path '"
......@@ -427,17 +428,13 @@ int NXTransClient(const char* display)
#ifdef __sun
snprintf(newDisplay, DISPLAY_LENGTH_LIMIT - 1, "DISPLAY=%s", display);
newDisplay[DISPLAY_LENGTH_LIMIT - 1] = '\0';
snprintf(newDisplay, DISPLAY_LENGTH_LIMIT, "DISPLAY=%s", display);
putenv(newDisplay);
#else
strncpy(newDisplay, display, DISPLAY_LENGTH_LIMIT - 1);
newDisplay[DISPLAY_LENGTH_LIMIT - 1] = '\0';
snprintf(newDisplay, DISPLAY_LENGTH_LIMIT, "%s", display);
setenv("DISPLAY", newDisplay, 1);
......@@ -467,6 +464,7 @@ int NXTransClient(const char* display)
if (i == 0)
{
// FIXME: code dpulication: this whole block is duplicated in NXTransDialog
strcpy(command, "nxclient");
char newPath[DEFAULT_STRING_LIMIT];
......@@ -489,7 +487,8 @@ int NXTransClient(const char* display)
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';
......
......@@ -70,6 +70,13 @@ EncodeBuffer::EncodeBuffer()
initialSize_ = ENCODE_BUFFER_DEFAULT_SIZE;
thresholdSize_ = ENCODE_BUFFER_DEFAULT_SIZE << 1;
maximumSize_ = ENCODE_BUFFER_DEFAULT_SIZE << 4;
#ifdef VALGRIND
memset(buffer_, '\0', size_);
#endif
}
EncodeBuffer::~EncodeBuffer()
......@@ -101,7 +108,15 @@ void EncodeBuffer::fullReset()
size_ = initialSize_;
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_;
......
......@@ -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 "
......
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