trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sudhe...@apache.org
Subject [trafficserver] 01/02: Preserve the raw log fields when wiping using case insensitive contains
Date Wed, 31 Jul 2019 23:37:07 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit 1df04706d5f28ec11fdebdfc1d03b6df7e46673b
Author: Sudheer Vinukonda <sudheerv@apache.org>
AuthorDate: Thu Jul 25 16:58:25 2019 -0700

    Preserve the raw log fields when wiping using case insensitive contains
    
    Fix clang error
---
 proxy/logging/LogFilter.cc | 26 ++++++++++++++++++--------
 proxy/logging/LogFilter.h  | 40 ++++++++++++++++++++++------------------
 2 files changed, 40 insertions(+), 26 deletions(-)

diff --git a/proxy/logging/LogFilter.cc b/proxy/logging/LogFilter.cc
index b80887d..bebab28 100644
--- a/proxy/logging/LogFilter.cc
+++ b/proxy/logging/LogFilter.cc
@@ -313,9 +313,12 @@ LogFilterString::wipe_this_entry(LogAccess *lad)
 
   static const unsigned BUFSIZE = 1024;
   char small_buf[BUFSIZE];
-  char *big_buf    = nullptr;
-  char *buf        = small_buf;
-  size_t marsh_len = m_field->marshal_len(lad); // includes null termination
+  char small_buf_upper[BUFSIZE];
+  char *big_buf       = nullptr;
+  char *big_buf_upper = nullptr;
+  char *buf           = small_buf;
+  char *buf_upper     = small_buf_upper;
+  size_t marsh_len    = m_field->marshal_len(lad); // includes null termination
 
   if (marsh_len > BUFSIZE) {
     big_buf = (char *)ats_malloc(marsh_len);
@@ -339,19 +342,25 @@ LogFilterString::wipe_this_entry(LogAccess *lad)
     // actual length, so we just use the fact that a MATCH is not possible
     // when marsh_len <= (length of the filter string)
     //
-    cond_satisfied = _checkConditionAndWipe(&strcmp, &buf, marsh_len, m_value, DATA_LENGTH_LARGER);
+    cond_satisfied = _checkConditionAndWipe(&strcmp, &buf, marsh_len, m_value, nullptr,
DATA_LENGTH_LARGER);
     break;
   case CASE_INSENSITIVE_MATCH:
-    cond_satisfied = _checkConditionAndWipe(&strcasecmp, &buf, marsh_len, m_value,
DATA_LENGTH_LARGER);
+    cond_satisfied = _checkConditionAndWipe(&strcasecmp, &buf, marsh_len, m_value,
nullptr, DATA_LENGTH_LARGER);
     break;
   case CONTAIN:
-    cond_satisfied = _checkConditionAndWipe(&_isSubstring, &buf, marsh_len, m_value,
DATA_LENGTH_LARGER);
+    cond_satisfied = _checkConditionAndWipe(&_isSubstring, &buf, marsh_len, m_value,
nullptr, DATA_LENGTH_LARGER);
     break;
   case CASE_INSENSITIVE_CONTAIN:
+    if (big_buf) {
+      big_buf_upper = (char *)ats_malloc((unsigned int)marsh_len);
+      buf_upper     = big_buf_upper;
+    } else {
+      buf = small_buf; // make clang happy
+    }
     for (size_t i = 0; i < marsh_len; i++) {
-      buf[i] = ParseRules::ink_toupper(buf[i]);
+      buf_upper[i] = ParseRules::ink_toupper(buf[i]);
     }
-    cond_satisfied = _checkConditionAndWipe(&_isSubstring, &buf, marsh_len, m_value_uppercase,
DATA_LENGTH_LARGER);
+    cond_satisfied = _checkConditionAndWipe(&_isSubstring, &buf_upper, marsh_len,
m_value_uppercase, &buf, DATA_LENGTH_LARGER);
     break;
   default:
     ink_assert(!"INVALID FILTER OPERATOR");
@@ -360,6 +369,7 @@ LogFilterString::wipe_this_entry(LogAccess *lad)
   m_field->updateField(lad, buf, strlen(buf));
 
   ats_free(big_buf);
+  ats_free(big_buf_upper);
   return cond_satisfied;
 }
 
diff --git a/proxy/logging/LogFilter.h b/proxy/logging/LogFilter.h
index 4fe7c8e..45a2440 100644
--- a/proxy/logging/LogFilter.h
+++ b/proxy/logging/LogFilter.h
@@ -171,7 +171,7 @@ private:
                               LengthCondition lc);
 
   inline bool _checkConditionAndWipe(OperatorFunction f, char **field_value, size_t field_value_length,
char **val,
-                                     LengthCondition lc);
+                                     char **orig_field_value, LengthCondition lc);
 
   // -- member functions that are not allowed --
   LogFilterString();
@@ -388,24 +388,28 @@ LogFilterString::_checkCondition(OperatorFunction f, const char *field_value,
si
 
 --------------------------------------------------------------------------*/
 static void
-wipeField(char **dest, char *field)
+wipeField(char **dest, char *field, char **orig_dest)
 {
-  char *buf_dest = *dest;
+  char *buf_dest      = *dest;
+  char *buf_orig_dest = orig_dest ? *orig_dest : *dest;
 
   if (buf_dest) {
-    char *query_param = strstr(buf_dest, "?");
+    char *query_param      = strstr(buf_dest, "?");
+    char *orig_query_param = strstr(buf_orig_dest, "?");
 
-    if (!query_param) {
+    if (!query_param || !orig_query_param) {
       return;
     }
 
-    char *p1 = strstr(query_param, field);
+    char *p1      = strstr(query_param, field);
+    int field_pos = p1 - query_param;
+    p1            = orig_query_param + field_pos;
 
     if (p1) {
-      char tmp_text[strlen(buf_dest) + 10];
+      char tmp_text[strlen(buf_orig_dest) + 10];
       char *temp_text = tmp_text;
-      memcpy(temp_text, buf_dest, (p1 - buf_dest));
-      temp_text += (p1 - buf_dest);
+      memcpy(temp_text, buf_orig_dest, (p1 - buf_orig_dest));
+      temp_text += (p1 - buf_orig_dest);
       char *p2 = strstr(p1, "=");
       if (p2) {
         p2++;
@@ -417,9 +421,9 @@ wipeField(char **dest, char *field)
             temp_text[i] = 'X';
           }
           temp_text += (p3 - p2);
-          memcpy(temp_text, p3, ((buf_dest + strlen(buf_dest)) - p3));
+          memcpy(temp_text, p3, ((buf_orig_dest + strlen(buf_orig_dest)) - p3));
         } else {
-          for (int i = 0; i < ((buf_dest + strlen(buf_dest)) - p2); i++) {
+          for (int i = 0; i < ((buf_orig_dest + strlen(buf_orig_dest)) - p2); i++) {
             temp_text[i] = 'X';
           }
         }
@@ -427,8 +431,8 @@ wipeField(char **dest, char *field)
         return;
       }
 
-      tmp_text[strlen(buf_dest)] = '\0';
-      strcpy(*dest, tmp_text);
+      tmp_text[strlen(buf_orig_dest)] = '\0';
+      orig_dest ? strcpy(*orig_dest, tmp_text) : strcpy(*dest, tmp_text);
     }
   }
 }
@@ -454,7 +458,7 @@ wipeField(char **dest, char *field)
 
 inline bool
 LogFilterString::_checkConditionAndWipe(OperatorFunction f, char **field_value, size_t field_value_length,
char **val,
-                                        LengthCondition lc)
+                                        char **orig_field_value, LengthCondition lc)
 {
   bool retVal = false;
 
@@ -469,13 +473,13 @@ LogFilterString::_checkConditionAndWipe(OperatorFunction f, char **field_value,
     case DATA_LENGTH_EQUAL:
       retVal = (field_value_length == *m_length ? ((*f)(*field_value, *val) == 0 ? true :
false) : false);
       if (retVal) {
-        wipeField(field_value, *val);
+        wipeField(field_value, *val, orig_field_value);
       }
       break;
     case DATA_LENGTH_LARGER:
       retVal = (field_value_length > *m_length ? ((*f)(*field_value, *val) == 0 ? true
: false) : false);
       if (retVal) {
-        wipeField(field_value, *val);
+        wipeField(field_value, *val, orig_field_value);
       }
       break;
     default:
@@ -490,7 +494,7 @@ LogFilterString::_checkConditionAndWipe(OperatorFunction f, char **field_value,
         // condition is satisfied if f returns zero
         if (field_value_length == m_length[i] && (*f)(*field_value, val[i]) == 0)
{
           retVal = true;
-          wipeField(field_value, val[i]);
+          wipeField(field_value, val[i], orig_field_value);
         }
       }
       break;
@@ -499,7 +503,7 @@ LogFilterString::_checkConditionAndWipe(OperatorFunction f, char **field_value,
         // condition is satisfied if f returns zero
         if (field_value_length > m_length[i] && (*f)(*field_value, val[i]) ==
0) {
           retVal = true;
-          wipeField(field_value, val[i]);
+          wipeField(field_value, val[i], orig_field_value);
         }
       }
       break;


Mime
View raw message