From 52543481dd9a0fab39c3f55a80b68a0f6d5e17bd Mon Sep 17 00:00:00 2001 From: Arkshine Date: Thu, 31 Jul 2014 18:36:52 +0200 Subject: [PATCH] Geoip: Increase buffer and fix potential overflow crash. --- dlls/geoip/geoip_amxx.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/dlls/geoip/geoip_amxx.cpp b/dlls/geoip/geoip_amxx.cpp index e8e5d173..cda14490 100755 --- a/dlls/geoip/geoip_amxx.cpp +++ b/dlls/geoip/geoip_amxx.cpp @@ -84,7 +84,7 @@ bool lookupByIp(const char *ip, const char **path, MMDB_entry_data_s *result) const char *lookupString(const char *ip, const char **path, int *length = NULL) { - static char buffer[64]; + static char buffer[256]; // This should be large enough for long name in UTF-8. MMDB_entry_data_s result; if (!lookupByIp(ip, path, &result)) @@ -92,14 +92,18 @@ const char *lookupString(const char *ip, const char **path, int *length = NULL) return NULL; } + // Let's avoid a crash in case we go over the buffer size. + size_t maxLength = ke::Min(result.data_size, sizeof(buffer)); + + // Strings from database are not null terminated. + memcpy(buffer, result.utf8_string, maxLength); + buffer[result.data_size] = '\0'; + if (length) { - *length = result.data_size; + *length = maxLength; } - memcpy(buffer, result.utf8_string, result.data_size); - buffer[result.data_size] = '\0'; - return buffer; }