mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-25 15:07:28 +00:00
Implement proper bounds checks across the codebase (#681)
* Implement proper bounds checks across the codebase * Implement strnlen_s for cross platform
This commit is contained in:
parent
9813c3ed2c
commit
9e08bb20d2
@ -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;
|
||||
|
@ -46,17 +46,20 @@ 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
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user