From 7cba36627c9ec5de62d5e29d3ff2d77b216137b0 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 24 Mar 2022 14:02:57 +0100 Subject: [PATCH] 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. --- common/rfb/CConnection.cxx | 9 ++++++++- 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 -- 2.39.5