You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by ez...@apache.org on 2021/07/29 01:22:07 UTC

[trafficserver] branch master updated: Various maxmind_acl fixes (#8181)

This is an automated email from the ASF dual-hosted git repository.

eze pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 76c4bc0  Various maxmind_acl fixes (#8181)
76c4bc0 is described below

commit 76c4bc0f4f5a6443acee8931ebc90ee822718be9
Author: Evan Zelkowitz <ez...@apache.org>
AuthorDate: Wed Jul 28 18:21:59 2021 -0700

    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
---
 plugins/experimental/maxmind_acl/mmdb.cc | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/plugins/experimental/maxmind_acl/mmdb.cc b/plugins/experimental/maxmind_acl/mmdb.cc
index 02c1851..27e66e5 100644
--- a/plugins/experimental/maxmind_acl/mmdb.cc
+++ b/plugins/experimental/maxmind_acl/mmdb.cc
@@ -406,7 +406,16 @@ Acl::eval(TSRemapRequestInfo *rri, TSHttpTxn txnp)
 {
   bool ret = default_allow;
   int mmdb_error;
-  MMDB_lookup_result_s result = MMDB_lookup_sockaddr(&_mmdb, TSHttpTxnClientAddrGet(txnp), &mmdb_error);
+
+  auto sockaddr = TSHttpTxnClientAddrGet(txnp);
+
+  if (sockaddr == nullptr) {
+    TSDebug(PLUGIN_NAME, "Err during TsHttpClientAddrGet, nullptr returned");
+    ret = false;
+    return ret;
+  }
+
+  MMDB_lookup_result_s result = MMDB_lookup_sockaddr(&_mmdb, sockaddr, &mmdb_error);
 
   if (MMDB_SUCCESS != mmdb_error) {
     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)
   bool ret     = false;
   bool allow   = default_allow;
   char *output = nullptr;
-  output       = static_cast<char *>(malloc((sizeof(char) * entry_data->data_size)));
+
+  // We need to null terminate the iso_code ourselves, they are unterminated in the DBs
+  output = static_cast<char *>(malloc((sizeof(char) * (entry_data->data_size + 1))));
   strncpy(output, entry_data->utf8_string, entry_data->data_size);
+  output[entry_data->data_size] = '\0';
   TSDebug(PLUGIN_NAME, "This IP Country Code: %s", output);
   auto exists = allow_country.count(output);