diff options
author | Pierre Ossman <ossman@cendio.se> | 2022-03-24 14:02:57 +0100 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2022-03-24 14:02:57 +0100 |
commit | 7cba36627c9ec5de62d5e29d3ff2d77b216137b0 (patch) | |
tree | 165bfb2bc5d1bf0c7bce3265ab25d4dda050e887 | |
parent | adc4570b191bc3576cae9f1074b37a3d31252e69 (diff) | |
download | tigervnc-7cba36627c9ec5de62d5e29d3ff2d77b216137b0.tar.gz tigervnc-7cba36627c9ec5de62d5e29d3ff2d77b216137b0.zip |
Make sure server name is always a valid string
Otherwise we can get crashes on NULL dereference. This should only
happen on reverse connections where we don't have a server address.
-rw-r--r-- | common/rfb/CConnection.cxx | 9 | ||||
-rw-r--r-- | common/rfb/CConnection.h | 2 |
2 files changed, 9 insertions, 2 deletions
diff --git a/common/rfb/CConnection.cxx b/common/rfb/CConnection.cxx index c474921b..675b49d6 100644 --- a/common/rfb/CConnection.cxx +++ b/common/rfb/CConnection.cxx @@ -52,7 +52,7 @@ CConnection::CConnection() supportsDesktopResize(false), supportsLEDState(false), is(0), os(0), reader_(0), writer_(0), shared(false), - state_(RFBSTATE_UNINITIALISED), + state_(RFBSTATE_UNINITIALISED), serverName(strDup("")), pendingPFChange(false), preferredEncoding(encodingTight), compressLevel(2), qualityLevel(-1), formatChange(false), encodingChange(false), @@ -68,6 +68,13 @@ CConnection::~CConnection() close(); } +void CConnection::setServerName(const char* name_) +{ + if (name_ == NULL) + name_ = ""; + serverName.replaceBuf(strDup(name_)); +} + void CConnection::setStreams(rdr::InStream* is_, rdr::OutStream* os_) { is = is_; diff --git a/common/rfb/CConnection.h b/common/rfb/CConnection.h index d5d07ca0..68554b59 100644 --- a/common/rfb/CConnection.h +++ b/common/rfb/CConnection.h @@ -48,7 +48,7 @@ namespace rfb { // which we are connected. This might be the result of getPeerEndpoint on // a TcpSocket, for example, or a host specified by DNS name & port. // The serverName is used when verifying the Identity of a host (see RA2). - void setServerName(const char* name_) { serverName.replaceBuf(strDup(name_)); } + void setServerName(const char* name_); // setStreams() sets the streams to be used for the connection. These must // be set before initialiseProtocol() and processMsg() are called. The |