char* name = inet_ntoa(addr);
if (name) {
- return rfb::strDup(name);
+ return safe_strdup(name);
} else {
- return rfb::strDup("");
+ return safe_strdup("");
}
}
char* name = inet_ntoa(addr);
if (name) {
- return rfb::strDup(name);
+ return safe_strdup(name);
} else {
- return rfb::strDup("");
+ return safe_strdup("");
}
}
TcpFilter::TcpFilter(const char* spec) {
rfb::CharArray tmp;
- tmp.buf = rfb::strDup(spec);
+ tmp.buf = safe_strdup(spec);
while (tmp.buf) {
rfb::CharArray first;
rfb::strSplit(tmp.buf, ',', &first.buf, &tmp.buf);
in_addr tmp;
rfb::CharArray addr, mask;
tmp.s_addr = p.address;
- addr.buf = rfb::strDup(inet_ntoa(tmp));
+ addr.buf = safe_strdup(inet_ntoa(tmp));
tmp.s_addr = p.mask;
- mask.buf = rfb::strDup(inet_ntoa(tmp));
+ mask.buf = safe_strdup(inet_ntoa(tmp));
char* result = new char[strlen(addr.buf)+1+strlen(mask.buf)+1+1];
switch (p.action) {
case Accept: result[0] = '+'; break;
*/
#include <rfb/Blacklist.h>
#include <rfb/Configuration.h>
+#include <stdlib.h>
using namespace rfb;
// Free the map keys
BlacklistMap::iterator i;
for (i=blm.begin(); i!=blm.end(); i++) {
- strFree((char*)(*i).first);
+ free((void *)(*i).first);
}
}
bi.marks = 1;
bi.blockUntil = 0;
bi.blockTimeout = initialTimeout;
- blm[strDup(name)] = bi;
+ blm[safe_strdup(name)] = bi;
i = blm.find(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);
}
}
}
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;
// 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
// -=- 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;
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");
}
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 {
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_);
}
StringParameter::~StringParameter() {
- strFree(value);
+ free(value);
}
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
void ConnParams::setName(const char* name)
{
delete [] name_;
- name_ = strDup(name);
+ name_ = safe_strdup(name);
}
void ConnParams::setEncodings(int nEncodings, const rdr::U32* encodings)
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
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] == ':') {
*port = basePort;
}
if (strlen(hostBuf.buf) == 0)
- *host = strDup("localhost");
+ *host = safe_strdup("localhost");
else
*host = hostBuf.takeBuf();
}
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);
}
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");
}
}
void Logger_File::setFilename(const char* filename)
{
closeFile();
- m_filename = strDup(filename);
+ m_filename = safe_strdup(filename);
}
void Logger_File::setFile(FILE* file)
fclose(m_file);
m_file = 0;
}
- strFree(m_filename);
+ free(m_filename);
m_filename = 0;
}
}
{
// 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);
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),
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++;
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);
#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.
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;
}
i+=increment;
}
- if (out1) *out1 = strDup(src);
+ if (out1) *out1 = safe_strdup(src);
if (out2) *out2 = 0;
return false;
}
#include <limits.h>
#include <string.h>
+char* safe_strdup(const char* s);
+
namespace rfb {
// -=- Class to handle cleanup of arrays of characters
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.
// setText() changes the text in the button.
void setText(const char* text_) {
- text.buf = rfb::strDup(text_);
+ text.buf = safe_strdup(text_);
int textWidth = XTextWidth(defaultFS, text.buf, strlen(text.buf));
int textHeight = (defaultFS->ascent + defaultFS->descent);
int newWidth = __rfbmax(width(), textWidth + xPad*2 + bevel*2);
// setText() changes the text in the label.
void setText(const char* text_) {
- text.buf = rfb::strDup(text_);
+ text.buf = safe_strdup(text_);
lines = 0;
int lineStart = 0;
int textWidth = 0;
void TXMenu::addEntry(const char* text_, long id_)
{
assert(nEntries < maxEntries);
- text[nEntries] = rfb::strDup(text_);
+ text[nEntries] = safe_strdup(text_);
checked[nEntries] = false;
id[nEntries++] = id_;
int tw = 0;
static char tickBits[] = { 0x80, 0xc0, 0xe2, 0x76, 0x3e, 0x1c, 0x08, 0x00};
tick = XCreateBitmapFromData(dpy, DefaultRootWindow(dpy), tickBits,
tickSize, tickSize);
- defaultWindowClass = rfb::strDup(defaultWindowClass_);
+ defaultWindowClass = safe_strdup(defaultWindowClass_);
}
void TXWindow::handleXEvents(Display* dpy)
PasswdDialog dlg(dpy, title.buf, !user);
if (!dlg.show()) throw rfb::Exception("Authentication cancelled");
if (user)
- *user = strDup(dlg.userEntry.getText());
- *password = strDup(dlg.passwdEntry.getText());
+ *user = safe_strdup(dlg.userEntry.getText());
+ *password = safe_strdup(dlg.passwdEntry.getText());
}
if (**vncServerName != '\0')
*remoteHost = *vncServerName;
- *gatewayHost = strDup (via.getValueStr ());
+ *gatewayHost = safe_strdup (via.getValueStr ());
*vncServerName = new char[50];
sprintf (*vncServerName, "localhost::%d", localPort);
}
const char* userName,
char** reason) {
if (queryConnectSock) {
- *reason = strDup("Another connection is currently being queried.");
+ *reason = safe_strdup("Another connection is currently being queried.");
return VNCServerST::REJECT;
}
if (!userName) userName = "(anonymous)";
char* XserverDesktop::substitute(const char* varName)
{
if (strcmp(varName, "$$") == 0) {
- return rfb::strDup("$");
+ return safe_strdup("$");
}
if (strcmp(varName, "$PORT") == 0) {
char* str = new char[10];
return str;
}
if (strcmp(varName, "$DESKTOP") == 0) {
- return rfb::strDup(server->getName());
+ return safe_strdup(server->getName());
}
if (strcmp(varName, "$DISPLAY") == 0) {
struct utsname uts;
}
if (strcmp(varName, "$USER") == 0) {
struct passwd* user = getpwuid(getuid());
- return rfb::strDup(user ? user->pw_name : "?");
+ return safe_strdup(user ? user->pw_name : "?");
}
return 0;
}
const char* userName,
char** reason) {
if (queryConnectId) {
- *reason = strDup("Another connection is currently being queried.");
+ *reason = safe_strdup("Another connection is currently being queried.");
return rfb::VNCServerST::REJECT;
}
queryConnectAddress.replaceBuf(sock->getPeerAddress());
if (!userName)
userName = "(anonymous)";
- queryConnectUsername.replaceBuf(strDup(userName));
+ queryConnectUsername.replaceBuf(safe_strdup(userName));
queryConnectId = sock;
vncQueryConnect(this, sock);
return rfb::VNCServerST::PENDING;