mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-15 11:03:00 +01:00
Check if memory was allocated successfully for server map
Somehow, there are cases where server thinks a map is around 2GiB in size. Such allocation will most likely fail on 32-bit system and crash the server. This provides *some* safety check and at least prevents server from crashing in such cases.
This commit is contained in:
@@ -1022,6 +1022,10 @@ void Network::Server_Send_MAP(NetworkConnection* connection)
|
||||
header = (unsigned char *)_strdup("open2_sv6_zlib");
|
||||
size_t header_len = strlen((char *)header) + 1; // account for null terminator
|
||||
header = (unsigned char *)realloc(header, header_len + out_size);
|
||||
if (header == nullptr) {
|
||||
log_error("Failed to allocate %u bytes.", header_len + out_size);
|
||||
return;
|
||||
}
|
||||
memcpy(&header[header_len], compressed, out_size);
|
||||
out_size += header_len;
|
||||
free(compressed);
|
||||
@@ -1029,6 +1033,10 @@ void Network::Server_Send_MAP(NetworkConnection* connection)
|
||||
} else {
|
||||
log_warning("Failed to compress the data, falling back to non-compressed sv6.");
|
||||
header = (unsigned char *)malloc(size);
|
||||
if (header == nullptr) {
|
||||
log_error("Failed to allocate %u bytes.", size);
|
||||
return;
|
||||
}
|
||||
out_size = size;
|
||||
memcpy(header, &buffer[0], size);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user