diff --git a/dCommon/dLogger.cpp b/dCommon/dLogger.cpp index 532a0cee..0beb5a3c 100644 --- a/dCommon/dLogger.cpp +++ b/dCommon/dLogger.cpp @@ -26,6 +26,13 @@ dLogger::~dLogger() { } void dLogger::vLog(const char* format, va_list args) { + const char* tempPtr = format; // strlen_s implementation for Linux and Windows + for (; *tempPtr != '\0'; ++tempPtr) { + size_t size = tempPtr - format; + if (size > 600) { + return; + } + } #ifdef _WIN32 time_t t = time(NULL); struct tm time; diff --git a/dNet/PacketUtils.cpp b/dNet/PacketUtils.cpp index a5d9f0ea..352f54b9 100644 --- a/dNet/PacketUtils.cpp +++ b/dNet/PacketUtils.cpp @@ -46,22 +46,25 @@ int64_t PacketUtils::ReadPacketS64(uint32_t startLoc, Packet * packet) { return *(int64_t*)t.data(); } -std::string PacketUtils::ReadString(uint32_t startLoc, Packet* packet, bool wide) { - std::string readString = ""; - +std::string PacketUtils::ReadString(uint32_t startLoc, Packet* packet, bool wide, uint32_t maxLen) { + std::string readString = ""; + + if (wide) maxLen *= 2; + if (packet->length > startLoc) { uint32_t i = 0; - while (packet->data[startLoc + i] != '\0' && packet->length > (uint32_t)(startLoc + i)) { + while (packet->data[startLoc + i] != '\0' && packet->length > (uint32_t)(startLoc + i) && maxLen > i) { readString.push_back(packet->data[startLoc + i]); - + if (wide) { i += 2; // Wide-char string - } else { + } + else { i++; // Regular string } } } - + return readString; } diff --git a/dNet/PacketUtils.h b/dNet/PacketUtils.h index 3426c3ab..61517ccf 100644 --- a/dNet/PacketUtils.h +++ b/dNet/PacketUtils.h @@ -11,7 +11,7 @@ namespace PacketUtils { uint32_t ReadPacketU32(uint32_t startLoc, Packet * packet); uint64_t ReadPacketU64(uint32_t startLoc, Packet * packet); int64_t ReadPacketS64(uint32_t startLoc, Packet * packet); - std::string ReadString(uint32_t startLoc, Packet * packet, bool wide); + std::string ReadString(uint32_t startLoc, Packet * packet, bool wide, uint32_t maxLen = 33); void WritePacketString(const std::string& string, uint32_t maxSize, RakNet::BitStream * bitStream); void WriteString(RakNet::BitStream& bitStream, const std::string& s, uint32_t maxSize);