#include <config.h>
#endif
+#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <os/Mutex.h>
-#include <rfb/util.h>
#include <rfb/Logger_file.h>
using namespace rfb;
Logger_File::Logger_File(const char* loggerName)
- : Logger(loggerName), indent(13), width(79), m_filename(0), m_file(0),
+ : Logger(loggerName), indent(13), width(79), m_file(0),
m_lastLogTime(0)
{
+ m_filename[0] = '\0';
mutex = new os::Mutex();
}
os::AutoMutex a(mutex);
if (!m_file) {
- if (!m_filename) return;
- CharArray bakFilename(strlen(m_filename) + 1 + 4);
- sprintf(bakFilename.buf, "%s.bak", m_filename);
- remove(bakFilename.buf);
- rename(m_filename, bakFilename.buf);
+ if (m_filename[0] == '\0')
+ return;
+ char bakFilename[PATH_MAX];
+ if (snprintf(bakFilename, sizeof(bakFilename),
+ "%s.bak", m_filename) >= (int)sizeof(bakFilename)) {
+ remove(m_filename);
+ } else {
+ remove(bakFilename);
+ rename(m_filename, bakFilename);
+ }
m_file = fopen(m_filename, "w+");
if (!m_file) return;
}
void Logger_File::setFilename(const char* filename)
{
closeFile();
- m_filename = strDup(filename);
+ m_filename[0] = '\0';
+ if (strlen(filename) >= sizeof(filename))
+ return;
+ strcpy(m_filename, filename);
}
void Logger_File::setFile(FILE* file)
void Logger_File::closeFile()
{
- if (m_filename) {
- if (m_file) {
- fclose(m_file);
- m_file = 0;
- }
- strFree(m_filename);
- m_filename = 0;
+ if (m_file) {
+ fclose(m_file);
+ m_file = 0;
}
}
#define __RFB_LOGGER_FILE_H__
#include <time.h>
+#include <limits.h>
+
#include <rfb/Logger.h>
namespace os { class Mutex; }
protected:
void closeFile();
- char* m_filename;
+ char m_filename[PATH_MAX];
FILE* m_file;
time_t m_lastLogTime;
os::Mutex* mutex;
bool SSecurityPlain::processMsg()
{
rdr::InStream* is = sc->getInStream();
- char* pw;
- char *uname;
- CharArray password;
+ char password[1024];
if (!valid)
throw AuthFailureException("No password validator configured");
return false;
ulen = is->readU32();
- if (ulen > MaxSaneUsernameLength)
+ if (ulen >= sizeof(username))
throw AuthFailureException("Too long username");
plen = is->readU32();
- if (plen > MaxSanePasswordLength)
+ if (plen >= sizeof(password))
throw AuthFailureException("Too long password");
state = 1;
if (!is->hasData(ulen + plen))
return false;
state = 2;
- pw = new char[plen + 1];
- uname = new char[ulen + 1];
- username.replaceBuf(uname);
- password.replaceBuf(pw);
- is->readBytes(uname, ulen);
- is->readBytes(pw, plen);
- pw[plen] = 0;
- uname[ulen] = 0;
+ is->readBytes(username, ulen);
+ is->readBytes(password, plen);
+ password[plen] = 0;
+ username[ulen] = 0;
plen = 0;
- if (!valid->validate(sc, uname, pw))
+ if (!valid->validate(sc, username, password))
throw AuthFailureException("invalid password or username");
}
#include <rfb/SConnection.h>
#include <rfb/SSecurity.h>
#include <rfb/SSecurityVeNCrypt.h>
-#include <rfb/util.h>
#include <rfb/Configuration.h>
namespace rfb {
SSecurityPlain(SConnection* sc);
virtual bool processMsg();
virtual int getType() const { return secTypePlain; };
- virtual const char* getUserName() const { return username.buf; }
+ virtual const char* getUserName() const { return username; }
virtual ~SSecurityPlain() { }
private:
PasswordValidator* valid;
unsigned int ulen, plen, state;
- CharArray username;
-
- static const unsigned int MaxSaneUsernameLength = 1024;
- static const unsigned int MaxSanePasswordLength = 1024;
+ char username[1024];
};
}
uint8_t lenUsername = rais->readU8();
if (!rais->hasDataOrRestore(lenUsername + 1))
return false;
- if (!username.buf) {
- username.replaceBuf(new char[lenUsername + 1]);
- rais->readBytes(username.buf, lenUsername);
- username.buf[lenUsername] = 0;
- } else {
- rais->skip(lenUsername);
- }
+ rais->readBytes(username, lenUsername);
+ username[lenUsername] = 0;
uint8_t lenPassword = rais->readU8();
if (!rais->hasDataOrRestore(lenPassword))
return false;
- password.replaceBuf(new char[lenPassword + 1]);
- rais->readBytes(password.buf, lenPassword);
- password.buf[lenPassword] = 0;
+ rais->readBytes(password, lenPassword);
+ password[lenPassword] = 0;
rais->clearRestorePoint();
return true;
}
#elif !defined(__APPLE__)
UnixPasswordValidator *valid = new UnixPasswordValidator();
#endif
- if (!valid->validate(sc, username.buf, password.buf)) {
+ if (!valid->validate(sc, username, password)) {
delete valid;
throw AuthFailureException("invalid password or username");
}
if (!passwd.buf)
throw AuthFailureException("No password configured for VNC Auth");
- if (strcmp(password.buf, passwd.buf) == 0) {
+ if (strcmp(password, passwd.buf) == 0) {
accessRights = SConnection::AccessDefault;
return;
}
- if (passwdReadOnly.buf && strcmp(password.buf, passwdReadOnly.buf) == 0) {
+ if (passwdReadOnly.buf && strcmp(password, passwdReadOnly.buf) == 0) {
accessRights = SConnection::AccessView;
return;
}
const char* SSecurityRSAAES::getUserName() const
{
- return username.buf;
+ return username;
}
uint8_t serverRandom[32];
uint8_t clientRandom[32];
- CharArray username;
- CharArray password;
+ char username[256];
+ char password[256];
SConnection::AccessRights accessRights;
rdr::InStream* rais;
#include <config.h>
#endif
+#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <os/os.h>
#include <rfb/Password.h>
-#include <rfb/util.h>
#include <termios.h>
{
prog = argv[0];
- char* fname = 0;
+ char fname[PATH_MAX];
+
+ fname[0] = '\0';
for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "-q") == 0) { // allowed for backwards compatibility
return encrypt_pipe();
} else if (argv[i][0] == '-') {
usage();
- } else if (!fname) {
- fname = strDup(argv[i]);
+ } else if (fname[0] == '\0') {
+ if (strlen(argv[i]) >= sizeof(fname)) {
+ fprintf(stderr, "Too long filename specified\n");
+ return -1;
+ }
+ strcpy(fname, argv[i]);
} else {
usage();
}
}
- if (!fname) {
+ if (fname[0] == '\0') {
const char *homeDir = os::getvnchomedir();
if (homeDir == NULL) {
fprintf(stderr, "Can't obtain VNC home directory\n");
exit(1);
}
mkdir(homeDir, 0777);
- fname = new char[strlen(homeDir) + strlen("/passwd") + 1];
- sprintf(fname, "%s/passwd", homeDir);
+ snprintf(fname, sizeof(fname), "%s/passwd", homeDir);
}
while (true) {
FILE* fp = fopen(fname,"w");
if (!fp) {
fprintf(stderr,"Couldn't open %s for writing\n",fname);
- delete [] fname;
delete obfuscated;
delete obfuscatedReadOnly;
exit(1);
if (fwrite(obfuscated->buf, obfuscated->length, 1, fp) != 1) {
fprintf(stderr,"Writing to %s failed\n",fname);
- delete [] fname;
delete obfuscated;
delete obfuscatedReadOnly;
exit(1);
if (obfuscatedReadOnly) {
if (fwrite(obfuscatedReadOnly->buf, obfuscatedReadOnly->length, 1, fp) != 1) {
fprintf(stderr,"Writing to %s failed\n",fname);
- delete [] fname;
delete obfuscatedReadOnly;
exit(1);
}
fclose(fp);
- delete [] fname;
delete obfuscatedReadOnly;
return 0;
void DesktopWindow::setName(const char *name)
{
- CharArray windowNameStr;
- windowNameStr.replaceBuf(new char[256]);
+ char windowNameStr[256];
- snprintf(windowNameStr.buf, 256, "%.240s - TigerVNC", name);
+ snprintf(windowNameStr, 256, "%.240s - TigerVNC", name);
- copy_label(windowNameStr.buf);
+ copy_label(windowNameStr);
}
#define __RFB_WIN32_COMPUTERNAME_H__
#include <windows.h>
-#include <rfb/util.h>
namespace rfb {
namespace win32 {
// Get the computer name
- struct ComputerName : CharArray {
- ComputerName() : CharArray(MAX_COMPUTERNAME_LENGTH+1) {
+ struct ComputerName {
+ ComputerName() {
ULONG namelength = MAX_COMPUTERNAME_LENGTH+1;
if (!GetComputerName(buf, &namelength))
strcpy(buf, "");
}
+ char buf[MAX_COMPUTERNAME_LENGTH+1];
};
};
#include <windows.h>
-#include <rfb/util.h>
-
namespace rfb {
namespace win32 {
- struct ModuleFileName : public CharArray {
- ModuleFileName(HMODULE module=0) : CharArray(MAX_PATH) {
+ struct ModuleFileName {
+ ModuleFileName(HMODULE module=0) {
if (!module)
module = GetModuleHandle(0);
if (!GetModuleFileName(module, buf, MAX_PATH))
buf[0] = 0;
}
+ char buf[MAX_PATH];
};
};
rfb::strSplit(tmp.buf, ':', &first.buf, &tmp.buf);
if (strlen(first.buf)) {
int bits = 0;
- CharArray pattern(1+4*4+4);
- pattern.buf[0] = first.buf[0];
- pattern.buf[1] = 0;
+ char pattern[1+4*4+4];
+ pattern[0] = first.buf[0];
+ pattern[1] = 0;
// Split the pattern into IP address parts and process
rfb::CharArray address;
rfb::CharArray part;
rfb::strSplit(address.buf, '.', &part.buf, &address.buf);
if (bits)
- strcat(pattern.buf, ".");
+ strcat(pattern, ".");
if (strlen(part.buf) > 3)
throw rdr::Exception("Invalid IP address part");
if (strlen(part.buf) > 0) {
- strcat(pattern.buf, part.buf);
+ strcat(pattern, part.buf);
bits += 8;
}
}
// Pad out the address specification if required
int addrBits = bits;
while (addrBits < 32) {
- if (addrBits) strcat(pattern.buf, ".");
- strcat(pattern.buf, "0");
+ if (addrBits) strcat(pattern, ".");
+ strcat(pattern, "0");
addrBits += 8;
}
// Append the number of bits to match
char buf[4];
sprintf(buf, "/%d", bits);
- strcat(pattern.buf, buf);
+ strcat(pattern, buf);
// Append this pattern to the Hosts value
- int length = strlen(newHosts.buf) + strlen(pattern.buf) + 2;
+ int length = strlen(newHosts.buf) + strlen(pattern) + 2;
CharArray tmpHosts(length);
- strcpy(tmpHosts.buf, pattern.buf);
+ strcpy(tmpHosts.buf, pattern);
if (strlen(newHosts.buf)) {
strcat(tmpHosts.buf, ",");
strcat(tmpHosts.buf, newHosts.buf);