aboutsummaryrefslogtreecommitdiff
path: root/src/server/shared
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2020-03-18 23:20:11 +0100
committerShauren <shauren.trinity@gmail.com>2021-12-23 23:55:58 +0100
commit3ebfa8cc645e5b35c8e6985ece3ef090858a9cb2 (patch)
tree66928fc63a6fbf82d61de23bde70a3b1de889be8 /src/server/shared
parentdef97385ccb3e81ae8e5661479118d12cf0372de (diff)
Core/PacketIO: Add a validating string helper class for use in packet classes
(cherry picked from commit f2f47f774f3d9c5da1a38b5f20cbfe59c2ff66af)
Diffstat (limited to 'src/server/shared')
-rw-r--r--src/server/shared/Packets/ByteBuffer.cpp12
-rw-r--r--src/server/shared/Packets/ByteBuffer.h2
2 files changed, 7 insertions, 7 deletions
diff --git a/src/server/shared/Packets/ByteBuffer.cpp b/src/server/shared/Packets/ByteBuffer.cpp
index 6c1ed3842cc..f8470332893 100644
--- a/src/server/shared/Packets/ByteBuffer.cpp
+++ b/src/server/shared/Packets/ByteBuffer.cpp
@@ -39,16 +39,16 @@ ByteBufferPositionException::ByteBufferPositionException(size_t pos, size_t size
message().assign(ss.str());
}
-ByteBufferInvalidValueException::ByteBufferInvalidValueException(char const* type, size_t pos)
+ByteBufferInvalidValueException::ByteBufferInvalidValueException(char const* type, char const* value)
{
- message().assign(Trinity::StringFormat("Invalid %s value found in ByteBuffer at pos " SZFMTD, type, pos));
+ message().assign(Trinity::StringFormat("Invalid %s value (%s) found in ByteBuffer", type, value));
}
ByteBuffer& ByteBuffer::operator>>(float& value)
{
value = read<float>();
if (!std::isfinite(value))
- throw ByteBufferInvalidValueException("float", _rpos - sizeof(float));
+ throw ByteBufferInvalidValueException("float", "infinity");
return *this;
}
@@ -56,7 +56,7 @@ ByteBuffer& ByteBuffer::operator>>(double& value)
{
value = read<double>();
if (!std::isfinite(value))
- throw ByteBufferInvalidValueException("double", _rpos - sizeof(double));
+ throw ByteBufferInvalidValueException("double", "infinity");
return *this;
}
@@ -71,7 +71,7 @@ std::string ByteBuffer::ReadCString(bool requireValidUtf8 /*= true*/)
value += c;
}
if (requireValidUtf8 && !utf8::is_valid(value.begin(), value.end()))
- throw ByteBufferInvalidValueException("string", _rpos - value.length() - 1);
+ throw ByteBufferInvalidValueException("string", value.c_str());
return value;
}
@@ -87,7 +87,7 @@ std::string ByteBuffer::ReadString(uint32 length, bool requireValidUtf8 /*= true
std::string value(reinterpret_cast<char const*>(&_storage[_rpos]), length);
_rpos += length;
if (requireValidUtf8 && !utf8::is_valid(value.begin(), value.end()))
- throw ByteBufferInvalidValueException("string", _rpos - value.length() - 1);
+ throw ByteBufferInvalidValueException("string", value.c_str());
return value;
}
diff --git a/src/server/shared/Packets/ByteBuffer.h b/src/server/shared/Packets/ByteBuffer.h
index 553c1a4c4ff..32f6bcbaee9 100644
--- a/src/server/shared/Packets/ByteBuffer.h
+++ b/src/server/shared/Packets/ByteBuffer.h
@@ -53,7 +53,7 @@ public:
class TC_SHARED_API ByteBufferInvalidValueException : public ByteBufferException
{
public:
- ByteBufferInvalidValueException(char const* type, size_t pos);
+ ByteBufferInvalidValueException(char const* type, char const* value);
~ByteBufferInvalidValueException() noexcept = default;
};