aboutsummaryrefslogtreecommitdiff
path: root/src/server/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/shared')
-rwxr-xr-xsrc/server/shared/Cryptography/HMACSHA1.cpp12
-rwxr-xr-xsrc/server/shared/Cryptography/HMACSHA1.h2
-rwxr-xr-xsrc/server/shared/Cryptography/SHA1.h1
-rwxr-xr-xsrc/server/shared/Packets/ByteBuffer.h84
4 files changed, 61 insertions, 38 deletions
diff --git a/src/server/shared/Cryptography/HMACSHA1.cpp b/src/server/shared/Cryptography/HMACSHA1.cpp
index 447d0b58efc..c9de1191464 100755
--- a/src/server/shared/Cryptography/HMACSHA1.cpp
+++ b/src/server/shared/Cryptography/HMACSHA1.cpp
@@ -31,19 +31,9 @@ HmacHash::~HmacHash()
HMAC_CTX_cleanup(&m_ctx);
}
-void HmacHash::UpdateBigNumber(BigNumber* bn)
-{
- UpdateData(bn->AsByteArray(), bn->GetNumBytes());
-}
-
-void HmacHash::UpdateData(const uint8 *data, int length)
-{
- HMAC_Update(&m_ctx, data, length);
-}
-
void HmacHash::UpdateData(const std::string &str)
{
- UpdateData((uint8 const*)str.c_str(), str.length());
+ HMAC_Update(&m_ctx, (uint8 const*)str.c_str(), str.length());
}
void HmacHash::Finalize()
diff --git a/src/server/shared/Cryptography/HMACSHA1.h b/src/server/shared/Cryptography/HMACSHA1.h
index bd0418b600e..4b7667968ca 100755
--- a/src/server/shared/Cryptography/HMACSHA1.h
+++ b/src/server/shared/Cryptography/HMACSHA1.h
@@ -33,8 +33,6 @@ class HmacHash
public:
HmacHash(uint32 len, uint8 *seed);
~HmacHash();
- void UpdateBigNumber(BigNumber* bn);
- void UpdateData(const uint8 *data, int length);
void UpdateData(const std::string &str);
void Finalize();
uint8 *ComputeHash(BigNumber* bn);
diff --git a/src/server/shared/Cryptography/SHA1.h b/src/server/shared/Cryptography/SHA1.h
index b5bf97fd7d9..7c77defebfa 100755
--- a/src/server/shared/Cryptography/SHA1.h
+++ b/src/server/shared/Cryptography/SHA1.h
@@ -31,7 +31,6 @@ class SHA1Hash
SHA1Hash();
~SHA1Hash();
- void UpdateFinalizeBigNumbers(BigNumber* bn0, ...);
void UpdateBigNumbers(BigNumber* bn0, ...);
void UpdateData(const uint8 *dta, int len);
diff --git a/src/server/shared/Packets/ByteBuffer.h b/src/server/shared/Packets/ByteBuffer.h
index 6b99b79625d..f018eb31bb4 100755
--- a/src/server/shared/Packets/ByteBuffer.h
+++ b/src/server/shared/Packets/ByteBuffer.h
@@ -27,22 +27,53 @@
class ByteBufferException
{
public:
- ByteBufferException(bool _add, size_t _pos, size_t _esize, size_t _size)
- : add(_add), pos(_pos), esize(_esize), size(_size)
+ ByteBufferException(size_t pos, size_t size, size_t valueSize)
+ : Pos(pos), Size(size), ValueSize(valueSize)
{
- PrintPosError();
}
- void PrintPosError() const
+ protected:
+
+ size_t Pos;
+ size_t Size;
+ size_t ValueSize;
+};
+
+class ByteBufferPositionException : public ByteBufferException
+{
+ public:
+ ByteBufferPositionException(bool add, size_t pos, size_t size, size_t valueSize)
+ : ByteBufferException(pos, size, valueSize), _add(add)
+ {
+ PrintError();
+ }
+
+ protected:
+ void PrintError() const
{
- sLog->outError("Attempted to %s in ByteBuffer (pos: " SIZEFMTD " size: "SIZEFMTD") value with size: " SIZEFMTD,
- (add ? "put" : "get"), pos, size, esize);
+ sLog->outError("Attempted to %s value with size: "SIZEFMTD" in ByteBuffer (pos: " SIZEFMTD " size: "SIZEFMTD") " ,
+ ValueSize, (_add ? "put" : "get"), Pos, Size);
}
+
private:
- bool add;
- size_t pos;
- size_t esize;
- size_t size;
+ bool _add;
+};
+
+class ByteBufferSourceException : public ByteBufferException
+{
+ public:
+ ByteBufferSourceException(size_t pos, size_t size, size_t valueSize)
+ : ByteBufferException(pos, size, valueSize)
+ {
+ PrintError();
+ }
+
+ protected:
+ void PrintError() const
+ {
+ sLog->outError("Attempted to put a %s in ByteBuffer (pos: "SIZEFMTD" size: "SIZEFMTD")",
+ (ValueSize > 0 ? "NULL-pointer" : "zero-sized value"), Pos, Size);
+ }
};
class ByteBuffer
@@ -147,14 +178,17 @@ class ByteBuffer
ByteBuffer &operator<<(const std::string &value)
{
- append((uint8 const*)value.c_str(), value.length());
+ if (size_t len = value.length())
+ append((uint8 const*)value.c_str(), len);
append((uint8)0);
return *this;
}
ByteBuffer &operator<<(const char *str)
{
- append((uint8 const*)str, str ? strlen(str) : 0);
+ size_t len = 0;
+ if (str && (len = strlen(str)))
+ append((uint8 const*)str, len);
append((uint8)0);
return *this;
}
@@ -271,7 +305,7 @@ class ByteBuffer
void read_skip(size_t skip)
{
if (_rpos + skip > size())
- throw ByteBufferException(false, _rpos, skip, size());
+ throw ByteBufferPositionException(false, _rpos, skip, size());
_rpos += skip;
}
@@ -285,7 +319,7 @@ class ByteBuffer
template <typename T> T read(size_t pos) const
{
if (pos + sizeof(T) > size())
- throw ByteBufferException(false, pos, sizeof(T), size());
+ throw ByteBufferPositionException(false, pos, sizeof(T), size());
T val = *((T const*)&_storage[pos]);
EndianConvert(val);
return val;
@@ -294,7 +328,7 @@ class ByteBuffer
void read(uint8 *dest, size_t len)
{
if (_rpos + len > size())
- throw ByteBufferException(false, _rpos, len, size());
+ throw ByteBufferPositionException(false, _rpos, len, size());
memcpy(dest, &_storage[_rpos], len);
_rpos += len;
}
@@ -302,7 +336,7 @@ class ByteBuffer
void readPackGUID(uint64& guid)
{
if (rpos() + 1 > size())
- throw ByteBufferException(false, _rpos, 1, size());
+ throw ByteBufferPositionException(false, _rpos, 1, size());
guid = 0;
@@ -314,7 +348,7 @@ class ByteBuffer
if (guidmark & (uint8(1) << i))
{
if (rpos() + 1 > size())
- throw ByteBufferException(false, _rpos, 1, size());
+ throw ByteBufferPositionException(false, _rpos, 1, size());
uint8 bit;
(*this) >> bit;
@@ -341,11 +375,6 @@ class ByteBuffer
_storage.reserve(ressize);
}
- void append(const std::string& str)
- {
- append((uint8 const*)str.c_str(), str.size() + 1);
- }
-
void append(const char *src, size_t cnt)
{
return append((const uint8 *)src, cnt);
@@ -359,7 +388,10 @@ class ByteBuffer
void append(const uint8 *src, size_t cnt)
{
if (!cnt)
- return;
+ throw ByteBufferSourceException(_wpos, size(), cnt);
+
+ if (!src)
+ throw ByteBufferSourceException(_wpos, size(), cnt);
ASSERT(size() < 10000000);
@@ -407,7 +439,11 @@ class ByteBuffer
void put(size_t pos, const uint8 *src, size_t cnt)
{
if (pos + cnt > size())
- throw ByteBufferException(true, pos, cnt, size());
+ throw ByteBufferPositionException(true, pos, cnt, size());
+
+ if (!src)
+ throw ByteBufferSourceException(_wpos, size(), cnt);
+
memcpy(&_storage[pos], src, cnt);
}