aboutsummaryrefslogtreecommitdiffstats
path: root/common/rfb
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2019-09-23 11:00:17 +0200
committerPierre Ossman <ossman@cendio.se>2019-11-15 11:55:05 +0100
commit0943c006c7d900dfc0281639e992791d6c567438 (patch)
tree9393960c3d86df32f6186a6feeb4fecfec376699 /common/rfb
parent4ff58f0acaeb566b79ae12cf013b376eaaaab834 (diff)
downloadtigervnc-0943c006c7d900dfc0281639e992791d6c567438.tar.gz
tigervnc-0943c006c7d900dfc0281639e992791d6c567438.zip
Use size_t for lengths in stream objects
Provides safety against them accidentally becoming negative because of bugs in the calculations. Also does the same to CharArray and friends as they were strongly connection to the stream objects.
Diffstat (limited to 'common/rfb')
-rw-r--r--common/rfb/Configuration.cxx6
-rw-r--r--common/rfb/Configuration.h13
-rw-r--r--common/rfb/Password.cxx6
-rw-r--r--common/rfb/Password.h6
-rw-r--r--common/rfb/util.h2
5 files changed, 17 insertions, 16 deletions
diff --git a/common/rfb/Configuration.cxx b/common/rfb/Configuration.cxx
index ea000600..ceaefccb 100644
--- a/common/rfb/Configuration.cxx
+++ b/common/rfb/Configuration.cxx
@@ -421,7 +421,7 @@ StringParameter::operator const char *() const {
// -=- BinaryParameter
BinaryParameter::BinaryParameter(const char* name_, const char* desc_,
- const void* v, int l, ConfigurationObject co)
+ const void* v, size_t l, ConfigurationObject co)
: VoidParameter(name_, desc_, co), value(0), length(0), def_value((char*)v), def_length(l) {
if (l) {
value = new char[l];
@@ -441,7 +441,7 @@ bool BinaryParameter::setParam(const char* v) {
return rdr::HexInStream::hexStrToBin(v, &value, &length);
}
-void BinaryParameter::setParam(const void* v, int len) {
+void BinaryParameter::setParam(const void* v, size_t len) {
LOCK_CONFIG;
if (immutable) return;
vlog.debug("set %s(Binary)", getName());
@@ -462,7 +462,7 @@ char* BinaryParameter::getValueStr() const {
return rdr::HexOutStream::binToHexStr(value, length);
}
-void BinaryParameter::getData(void** data_, int* length_) const {
+void BinaryParameter::getData(void** data_, size_t* length_) const {
LOCK_CONFIG;
if (length_) *length_ = length;
if (data_) {
diff --git a/common/rfb/Configuration.h b/common/rfb/Configuration.h
index 6197317b..e23e8a51 100644
--- a/common/rfb/Configuration.h
+++ b/common/rfb/Configuration.h
@@ -256,24 +256,25 @@ namespace rfb {
class BinaryParameter : public VoidParameter {
public:
- BinaryParameter(const char* name_, const char* desc_, const void* v, int l,
- ConfigurationObject co=ConfGlobal);
+ BinaryParameter(const char* name_, const char* desc_,
+ const void* v, size_t l,
+ ConfigurationObject co=ConfGlobal);
using VoidParameter::setParam;
virtual ~BinaryParameter();
virtual bool setParam(const char* value);
- virtual void setParam(const void* v, int l);
+ virtual void setParam(const void* v, size_t l);
virtual char* getDefaultStr() const;
virtual char* getValueStr() const;
// getData() will return length zero if there is no data
// NB: data may be set to zero, OR set to a zero-length buffer
- void getData(void** data, int* length) const;
+ void getData(void** data, size_t* length) const;
protected:
char* value;
- int length;
+ size_t length;
char* def_value;
- int def_length;
+ size_t def_length;
};
// -=- ParameterIterator
diff --git a/common/rfb/Password.cxx b/common/rfb/Password.cxx
index 240c9d4f..e4a508c8 100644
--- a/common/rfb/Password.cxx
+++ b/common/rfb/Password.cxx
@@ -38,7 +38,7 @@ PlainPasswd::PlainPasswd() {}
PlainPasswd::PlainPasswd(char* pwd) : CharArray(pwd) {
}
-PlainPasswd::PlainPasswd(int len) : CharArray(len) {
+PlainPasswd::PlainPasswd(size_t len) : CharArray(len) {
}
PlainPasswd::PlainPasswd(const ObfuscatedPasswd& obfPwd) : CharArray(9) {
@@ -63,11 +63,11 @@ void PlainPasswd::replaceBuf(char* b) {
ObfuscatedPasswd::ObfuscatedPasswd() : length(0) {
}
-ObfuscatedPasswd::ObfuscatedPasswd(int len) : CharArray(len), length(len) {
+ObfuscatedPasswd::ObfuscatedPasswd(size_t len) : CharArray(len), length(len) {
}
ObfuscatedPasswd::ObfuscatedPasswd(const PlainPasswd& plainPwd) : CharArray(8), length(8) {
- int l = strlen(plainPwd.buf), i;
+ size_t l = strlen(plainPwd.buf), i;
for (i=0; i<8; i++)
buf[i] = i<l ? plainPwd.buf[i] : 0;
deskey(d3desObfuscationKey, EN0);
diff --git a/common/rfb/Password.h b/common/rfb/Password.h
index e5196ee0..712bc813 100644
--- a/common/rfb/Password.h
+++ b/common/rfb/Password.h
@@ -28,7 +28,7 @@ namespace rfb {
public:
PlainPasswd();
PlainPasswd(char* pwd);
- PlainPasswd(int len);
+ PlainPasswd(size_t len);
PlainPasswd(const ObfuscatedPasswd& obfPwd);
~PlainPasswd();
void replaceBuf(char* b);
@@ -37,10 +37,10 @@ namespace rfb {
class ObfuscatedPasswd : public CharArray {
public:
ObfuscatedPasswd();
- ObfuscatedPasswd(int l);
+ ObfuscatedPasswd(size_t l);
ObfuscatedPasswd(const PlainPasswd& plainPwd);
~ObfuscatedPasswd();
- int length;
+ size_t length;
};
}
diff --git a/common/rfb/util.h b/common/rfb/util.h
index 8503519d..3100f90f 100644
--- a/common/rfb/util.h
+++ b/common/rfb/util.h
@@ -50,7 +50,7 @@ namespace rfb {
public:
CharArray() : buf(0) {}
CharArray(char* str) : buf(str) {} // note: assumes ownership
- CharArray(int len) {
+ CharArray(size_t len) {
buf = new char[len]();
}
~CharArray() {