Skip to content

Commit 76c4bc0

Browse files
authored
Various maxmind_acl fixes (#8181)
* Various maxmind_acl fixes - Add a check for non-nullptr client addr - Add null termination for iso_codes. They are stored unterminated in the database so to properly lookup in the map we need to terminate ourselves * Review fixes
1 parent e6a7603 commit 76c4bc0

File tree

1 file changed

+14
-2
lines changed
  • plugins/experimental/maxmind_acl

1 file changed

+14
-2
lines changed

plugins/experimental/maxmind_acl/mmdb.cc

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,16 @@ Acl::eval(TSRemapRequestInfo *rri, TSHttpTxn txnp)
406406
{
407407
bool ret = default_allow;
408408
int mmdb_error;
409-
MMDB_lookup_result_s result = MMDB_lookup_sockaddr(&_mmdb, TSHttpTxnClientAddrGet(txnp), &mmdb_error);
409+
410+
auto sockaddr = TSHttpTxnClientAddrGet(txnp);
411+
412+
if (sockaddr == nullptr) {
413+
TSDebug(PLUGIN_NAME, "Err during TsHttpClientAddrGet, nullptr returned");
414+
ret = false;
415+
return ret;
416+
}
417+
418+
MMDB_lookup_result_s result = MMDB_lookup_sockaddr(&_mmdb, sockaddr, &mmdb_error);
410419

411420
if (MMDB_SUCCESS != mmdb_error) {
412421
TSDebug(PLUGIN_NAME, "Error during sockaddr lookup: %s", MMDB_strerror(mmdb_error));
@@ -498,8 +507,11 @@ Acl::eval_country(MMDB_entry_data_s *entry_data, const char *path, int path_len)
498507
bool ret = false;
499508
bool allow = default_allow;
500509
char *output = nullptr;
501-
output = static_cast<char *>(malloc((sizeof(char) * entry_data->data_size)));
510+
511+
// We need to null terminate the iso_code ourselves, they are unterminated in the DBs
512+
output = static_cast<char *>(malloc((sizeof(char) * (entry_data->data_size + 1))));
502513
strncpy(output, entry_data->utf8_string, entry_data->data_size);
514+
output[entry_data->data_size] = '\0';
503515
TSDebug(PLUGIN_NAME, "This IP Country Code: %s", output);
504516
auto exists = allow_country.count(output);
505517

0 commit comments

Comments
 (0)