summaryrefslogtreecommitdiffstats
path: root/common/rfb
diff options
context:
space:
mode:
authorAdam Tkac <atkac@redhat.com>2009-09-04 10:16:58 +0000
committerAdam Tkac <atkac@redhat.com>2009-09-04 10:16:58 +0000
commit97abe8a548ff9ca940d568128b21813b8a253872 (patch)
treed38ea6a539b2cc4e70d9569e71985914818546cd /common/rfb
parent8ed9009b4c4f497a95114d878334de3e13457bdd (diff)
downloadtigervnc-97abe8a548ff9ca940d568128b21813b8a253872.tar.gz
tigervnc-97abe8a548ff9ca940d568128b21813b8a253872.zip
Replace rfb::strDup by safe_strdup and remove rfb::strFree in favor of free()
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@3889 3789f03b-4d11-0410-bbf8-ca57d06f2519
Diffstat (limited to 'common/rfb')
-rw-r--r--common/rfb/Blacklist.cxx7
-rw-r--r--common/rfb/CConnection.cxx2
-rw-r--r--common/rfb/CConnection.h2
-rw-r--r--common/rfb/Configuration.cxx18
-rw-r--r--common/rfb/ConnParams.cxx2
-rw-r--r--common/rfb/HTTPServer.cxx2
-rw-r--r--common/rfb/Hostname.h4
-rw-r--r--common/rfb/ListConnInfo.h12
-rw-r--r--common/rfb/Logger_file.cxx4
-rw-r--r--common/rfb/VNCSConnectionST.cxx2
-rw-r--r--common/rfb/VNCServerST.cxx4
-rw-r--r--common/rfb/secTypes.cxx2
-rw-r--r--common/rfb/util.cxx28
-rw-r--r--common/rfb/util.h5
14 files changed, 47 insertions, 47 deletions
diff --git a/common/rfb/Blacklist.cxx b/common/rfb/Blacklist.cxx
index 4590befe..1db2995c 100644
--- a/common/rfb/Blacklist.cxx
+++ b/common/rfb/Blacklist.cxx
@@ -17,6 +17,7 @@
*/
#include <rfb/Blacklist.h>
#include <rfb/Configuration.h>
+#include <stdlib.h>
using namespace rfb;
@@ -37,7 +38,7 @@ Blacklist::~Blacklist() {
// Free the map keys
BlacklistMap::iterator i;
for (i=blm.begin(); i!=blm.end(); i++) {
- strFree((char*)(*i).first);
+ free((void *)(*i).first);
}
}
@@ -51,7 +52,7 @@ bool Blacklist::isBlackmarked(const char* name) {
bi.marks = 1;
bi.blockUntil = 0;
bi.blockTimeout = initialTimeout;
- blm[strDup(name)] = bi;
+ blm[safe_strdup(name)] = bi;
i = blm.find(name);
}
@@ -80,7 +81,7 @@ bool Blacklist::isBlackmarked(const char* name) {
void Blacklist::clearBlackmark(const char* name) {
BlacklistMap::iterator i = blm.find(name);
if (i != blm.end()) {
- strFree((char*)(*i).first);
+ free((void *)(*i).first);
blm.erase(i);
}
}
diff --git a/common/rfb/CConnection.cxx b/common/rfb/CConnection.cxx
index 36778f02..59955696 100644
--- a/common/rfb/CConnection.cxx
+++ b/common/rfb/CConnection.cxx
@@ -234,7 +234,7 @@ void CConnection::processSecurityResultMsg()
}
CharArray reason;
if (cp.beforeVersion(3,8))
- reason.buf = strDup("Authentication failure");
+ reason.buf = safe_strdup("Authentication failure");
else
reason.buf = is->readString();
state_ = RFBSTATE_INVALID;
diff --git a/common/rfb/CConnection.h b/common/rfb/CConnection.h
index 79110eb9..b3fd093f 100644
--- a/common/rfb/CConnection.h
+++ b/common/rfb/CConnection.h
@@ -47,7 +47,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_) { serverName.replaceBuf(safe_strdup(name_)); }
// setStreams() sets the streams to be used for the connection. These must
// be set before initialiseProtocol() and processMsg() are called. The
diff --git a/common/rfb/Configuration.cxx b/common/rfb/Configuration.cxx
index 9ebc20a8..fd4c23ae 100644
--- a/common/rfb/Configuration.cxx
+++ b/common/rfb/Configuration.cxx
@@ -67,7 +67,7 @@ Configuration* Configuration::global() {
// -=- Configuration implementation
Configuration::Configuration(const char* name_, Configuration* attachToGroup)
-: name(strDup(name_)), head(0), _next(0) {
+: name(safe_strdup(name_)), head(0), _next(0) {
if (attachToGroup) {
_next = attachToGroup->_next;
attachToGroup->_next = this;
@@ -182,7 +182,7 @@ void Configuration::list(int width, int nameWidth) {
if (column + (int)strlen(def_str) + 11 > width)
fprintf(stderr,"\n%*s",nameWidth+4,"");
fprintf(stderr," (default=%s)\n",def_str);
- strFree(def_str);
+ free(def_str);
} else {
fprintf(stderr,"\n");
}
@@ -315,11 +315,11 @@ void BoolParameter::setParam(bool b) {
char*
BoolParameter::getDefaultStr() const {
- return strDup(def_value ? "1" : "0");
+ return safe_strdup(def_value ? "1" : "0");
}
char* BoolParameter::getValueStr() const {
- return strDup(value ? "1" : "0");
+ return safe_strdup(value ? "1" : "0");
}
bool BoolParameter::isBool() const {
@@ -381,7 +381,7 @@ IntParameter::operator int() const {
StringParameter::StringParameter(const char* name_, const char* desc_,
const char* v, Configuration* conf)
- : VoidParameter(name_, desc_, conf), value(strDup(v)), def_value(v)
+ : VoidParameter(name_, desc_, conf), value(safe_strdup(v)), def_value(v)
{
if (!v) {
fprintf(stderr,"Default value <null> for %s not allowed\n",name_);
@@ -390,7 +390,7 @@ StringParameter::StringParameter(const char* name_, const char* desc_,
}
StringParameter::~StringParameter() {
- strFree(value);
+ free(value);
}
bool StringParameter::setParam(const char* v) {
@@ -400,17 +400,17 @@ bool StringParameter::setParam(const char* v) {
throw rfb::Exception("setParam(<null>) not allowed");
vlog.debug("set %s(String) to %s", getName(), v);
CharArray oldValue(value);
- value = strDup(v);
+ value = safe_strdup(v);
return value != 0;
}
char* StringParameter::getDefaultStr() const {
- return strDup(def_value);
+ return safe_strdup(def_value);
}
char* StringParameter::getValueStr() const {
LOCK_CONFIG;
- return strDup(value);
+ return safe_strdup(value);
}
// -=- BinaryParameter
diff --git a/common/rfb/ConnParams.cxx b/common/rfb/ConnParams.cxx
index 7b27a734..4bbd2cbe 100644
--- a/common/rfb/ConnParams.cxx
+++ b/common/rfb/ConnParams.cxx
@@ -82,7 +82,7 @@ void ConnParams::setPF(const PixelFormat& pf)
void ConnParams::setName(const char* name)
{
delete [] name_;
- name_ = strDup(name);
+ name_ = safe_strdup(name);
}
void ConnParams::setEncodings(int nEncodings, const rdr::U32* encodings)
diff --git a/common/rfb/HTTPServer.cxx b/common/rfb/HTTPServer.cxx
index 94f06090..934ca74e 100644
--- a/common/rfb/HTTPServer.cxx
+++ b/common/rfb/HTTPServer.cxx
@@ -240,7 +240,7 @@ HTTPServer::Session::processHTTP() {
return writeResponse(501);
// Store the URI to the "document"
- uri.buf = strDup(path);
+ uri.buf = safe_strdup(path);
}
// Move on to reading the request headers
diff --git a/common/rfb/Hostname.h b/common/rfb/Hostname.h
index ebdf816f..d7ff664e 100644
--- a/common/rfb/Hostname.h
+++ b/common/rfb/Hostname.h
@@ -32,7 +32,7 @@ namespace rfb {
if (!strSplit(&hi[1], ']', &hostBuf.buf, &portBuf.buf))
throw rdr::Exception("unmatched [ in host");
} else {
- portBuf.buf = strDup(hi);
+ portBuf.buf = safe_strdup(hi);
}
if (strSplit(portBuf.buf, ':', hostBuf.buf ? 0 : &hostBuf.buf, &portBuf.buf)) {
if (portBuf.buf[0] == ':') {
@@ -45,7 +45,7 @@ namespace rfb {
*port = basePort;
}
if (strlen(hostBuf.buf) == 0)
- *host = strDup("localhost");
+ *host = safe_strdup("localhost");
else
*host = hostBuf.takeBuf();
}
diff --git a/common/rfb/ListConnInfo.h b/common/rfb/ListConnInfo.h
index cabcbc79..6e4eacc5 100644
--- a/common/rfb/ListConnInfo.h
+++ b/common/rfb/ListConnInfo.h
@@ -52,8 +52,8 @@ namespace rfb {
void addInfo(void* Conn, char* IP, char* Time, int Status) {
conn.push_back(Conn);
- IP_address.push_back(strDup(IP));
- time_conn.push_back(strDup(Time));
+ IP_address.push_back(safe_strdup(IP));
+ time_conn.push_back(safe_strdup(Time));
status.push_back(Status);
}
@@ -62,16 +62,16 @@ namespace rfb {
buf[1] = *ti;
switch (*si) {
case 0:
- buf[2] = strDup("Full control");
+ buf[2] = safe_strdup("Full control");
break;
case 1:
- buf[2] = strDup("View only");
+ buf[2] = safe_strdup("View only");
break;
case 2:
- buf[2] = strDup("Stop updating");
+ buf[2] = safe_strdup("Stop updating");
break;
default:
- buf[2] = strDup("Unknown");
+ buf[2] = safe_strdup("Unknown");
}
}
diff --git a/common/rfb/Logger_file.cxx b/common/rfb/Logger_file.cxx
index 8a109e4a..cf195c0d 100644
--- a/common/rfb/Logger_file.cxx
+++ b/common/rfb/Logger_file.cxx
@@ -97,7 +97,7 @@ void Logger_File::write(int level, const char *logname, const char *message)
void Logger_File::setFilename(const char* filename)
{
closeFile();
- m_filename = strDup(filename);
+ m_filename = safe_strdup(filename);
}
void Logger_File::setFile(FILE* file)
@@ -113,7 +113,7 @@ void Logger_File::closeFile()
fclose(m_file);
m_file = 0;
}
- strFree(m_filename);
+ free(m_filename);
m_filename = 0;
}
}
diff --git a/common/rfb/VNCSConnectionST.cxx b/common/rfb/VNCSConnectionST.cxx
index e286cf31..0006ff20 100644
--- a/common/rfb/VNCSConnectionST.cxx
+++ b/common/rfb/VNCSConnectionST.cxx
@@ -89,7 +89,7 @@ void VNCSConnectionST::close(const char* reason)
{
// Log the reason for the close
if (!closeReason.buf)
- closeReason.buf = strDup(reason);
+ closeReason.buf = safe_strdup(reason);
else
vlog.debug("second close: %s (%s)", peerEndpoint.buf, reason);
diff --git a/common/rfb/VNCServerST.cxx b/common/rfb/VNCServerST.cxx
index a21526ad..5be63969 100644
--- a/common/rfb/VNCServerST.cxx
+++ b/common/rfb/VNCServerST.cxx
@@ -74,7 +74,7 @@ static SSecurityFactoryStandard defaultSecurityFactory;
VNCServerST::VNCServerST(const char* name_, SDesktop* desktop_,
SSecurityFactory* sf)
: blHosts(&blacklist), desktop(desktop_), desktopStarted(false), pb(0),
- name(strDup(name_)), pointerClient(0), comparer(0),
+ name(safe_strdup(name_)), pointerClient(0), comparer(0),
renderedCursorInvalid(false),
securityFactory(sf ? sf : &defaultSecurityFactory),
queryConnectionHandler(0), keyRemapper(&KeyRemapper::defInstance),
@@ -363,7 +363,7 @@ void VNCServerST::serverCutText(const char* str, int len)
void VNCServerST::setName(const char* name_)
{
- name.replaceBuf(strDup(name_));
+ name.replaceBuf(safe_strdup(name_));
std::list<VNCSConnectionST*>::iterator ci, ci_next;
for (ci = clients.begin(); ci != clients.end(); ci = ci_next) {
ci_next = ci; ci_next++;
diff --git a/common/rfb/secTypes.cxx b/common/rfb/secTypes.cxx
index 830d8444..9ea6a000 100644
--- a/common/rfb/secTypes.cxx
+++ b/common/rfb/secTypes.cxx
@@ -62,7 +62,7 @@ bool rfb::secTypeEncrypts(int num)
std::list<int> rfb::parseSecTypes(const char* types_)
{
std::list<int> result;
- CharArray types(strDup(types_)), type;
+ CharArray types(safe_strdup(types_)), type;
while (types.buf) {
strSplit(types.buf, ',', &type.buf, &types.buf);
int typeNum = secTypeNum(type.buf);
diff --git a/common/rfb/util.cxx b/common/rfb/util.cxx
index a50ea586..7935a3a0 100644
--- a/common/rfb/util.cxx
+++ b/common/rfb/util.cxx
@@ -35,6 +35,19 @@
#endif
#include <rfb/util.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+char* safe_strdup(const char* s) {
+ char *tmp;
+
+ tmp = strdup(s);
+ if (tmp == NULL) {
+ perror("safe_strdup failed");
+ exit(1);
+ }
+};
// Provide strcasecmp() and/or strncasecmp() if absent on this system.
@@ -129,19 +142,6 @@ strncasecmp(const char *s1, const char *s2, size_t n)
namespace rfb {
- char* strDup(const char* s) {
- if (!s) return 0;
- int l = strlen(s);
- char* r = new char[l+1];
- memcpy(r, s, l+1);
- return r;
- };
-
- void strFree(char* s) {
- delete [] s;
- }
-
-
bool strSplit(const char* src, const char limiter, char** out1, char** out2, bool fromEnd) {
CharArray out1old, out2old;
if (out1) out1old.buf = *out1;
@@ -167,7 +167,7 @@ namespace rfb {
}
i+=increment;
}
- if (out1) *out1 = strDup(src);
+ if (out1) *out1 = safe_strdup(src);
if (out2) *out2 = 0;
return false;
}
diff --git a/common/rfb/util.h b/common/rfb/util.h
index 933df527..8bf54842 100644
--- a/common/rfb/util.h
+++ b/common/rfb/util.h
@@ -30,6 +30,8 @@
#include <limits.h>
#include <string.h>
+char* safe_strdup(const char* s);
+
namespace rfb {
// -=- Class to handle cleanup of arrays of characters
@@ -52,9 +54,6 @@ namespace rfb {
CharArray& operator=(const CharArray&);
};
- char* strDup(const char* s);
- void strFree(char* s);
-
// Returns true if split successful. Returns false otherwise.
// ALWAYS *copies* first part of string to out1 buffer.
// If limiter not found, leaves out2 alone (null) and just copies to out1.