trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From z..@apache.org
Subject [trafficserver] 02/06: fix the bug if filter word included in param value
Date Thu, 29 Aug 2019 06:39:39 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit 601d090b07f64a90cbf11bf55d6c1fad83f34f2d
Author: xinli1 <xinli1@linkedin.com>
AuthorDate: Thu Aug 15 11:54:41 2019 -0700

    fix the bug if filter word included in param value
---
 proxy/logging/LogFilter.h | 96 +++++++++++++++++++++++++----------------------
 1 file changed, 51 insertions(+), 45 deletions(-)

diff --git a/proxy/logging/LogFilter.h b/proxy/logging/LogFilter.h
index 19a1f3d..f7a945b 100644
--- a/proxy/logging/LogFilter.h
+++ b/proxy/logging/LogFilter.h
@@ -382,6 +382,30 @@ LogFilterString::_checkCondition(OperatorFunction f, const char *field_value,
si
   return retVal;
 }
 
+static const char *
+findPtternFromParamName(const char *lookup_query_param, const char *pattern)
+{
+  const char *p1 = strstr(lookup_query_param, pattern);
+  while (p1) {
+    // wipe pattern in param name, need search again if find pattern in param value
+    const char *p10 = strstr(p1, "=");
+    if (!p10) {
+      // no "=" after p1, means p1 is not in the param name, and no more param after it
+      p1 = nullptr;
+      break;
+    }
+    const char *p11 = strstr(p1, "&");
+    if (p11 && p10 > p11) {
+      //"=" is after "&" followd by p1, means p1 is not in the param name
+      p1 = strstr(p11, pattern);
+      continue;
+    }
+    // ensure p1 is in the param name now
+    break;
+  }
+  return p1;
+}
+
 /*---------------------------------------------------------------------------
   wipeField : Given a dest buffer, wipe the first occurrence of the value of the
   field in the buffer.
@@ -400,55 +424,37 @@ wipeField(char **field, char *pattern, const char *uppercase_field)
       return;
     }
 
-    const char *p1 = strstr(lookup_query_param, pattern);
-    if (!p1) {
-      return;
-    } else {
-      while(p1) {
-        //wipe pattern in param name, need search again if find pattern in param value
-        const char *p10 = strstr(p1, "=");
-        if (!p10) {
-          //no "=" after p1, means p1 is not in the param name, and no more param after it
-          return;
-        }
-        const char *p11 = strstr(p1, "&");
-        if (p11 && p10 > p11) {
-          //"=" is after "&" followd by p1, means p1 is not in the param name 
-          p1 = strstr(p11, pattern);
-          continue;
-        }
-
-        int field_pos  = p1 - lookup_query_param;
-        p1             = query_param + field_pos;
-
-        char tmp_text[strlen(buf_dest) + 10];
-        char *temp_text = tmp_text;
-        memcpy(temp_text, buf_dest, (p1 - buf_dest));
-        temp_text += (p1 - buf_dest);
-        const char *p2 = strstr(p1, "=");
-        if (p2) {
-          p2++;
-          memcpy(temp_text, p1, (p2 - p1));
-          temp_text += (p2 - p1);
-          const char *p3 = strstr(p2, "&");
-          if (p3) {
-            for (int i     = 0; i < (p3 - p2); i++)
-              temp_text[i] = 'X';
-            temp_text += (p3 - p2);
-            memcpy(temp_text, p3, ((buf_dest + strlen(buf_dest)) - p3));
-          } else {
-            for (int i     = 0; i < ((buf_dest + strlen(buf_dest)) - p2); i++) {
-              temp_text[i] = 'X';
-            }
-          }
+    const char *p1 = findPtternFromParamName(lookup_query_param, pattern);
+    if (p1) {
+      int field_pos = p1 - lookup_query_param;
+      p1            = query_param + field_pos;
+
+      char tmp_text[strlen(buf_dest) + 10];
+      char *temp_text = tmp_text;
+      memcpy(temp_text, buf_dest, (p1 - buf_dest));
+      temp_text += (p1 - buf_dest);
+      const char *p2 = strstr(p1, "=");
+      if (p2) {
+        p2++;
+        memcpy(temp_text, p1, (p2 - p1));
+        temp_text += (p2 - p1);
+        const char *p3 = strstr(p2, "&");
+        if (p3) {
+          for (int i = 0; i < (p3 - p2); i++)
+            temp_text[i] = 'X';
+          temp_text += (p3 - p2);
+          memcpy(temp_text, p3, ((buf_dest + strlen(buf_dest)) - p3));
         } else {
-          return;
+          for (int i = 0; i < ((buf_dest + strlen(buf_dest)) - p2); i++) {
+            temp_text[i] = 'X';
+          }
         }
-
-        tmp_text[strlen(buf_dest)] = '\0';
-        strcpy(*field, tmp_text);
+      } else {
         return;
       }
+
+      tmp_text[strlen(buf_dest)] = '\0';
+      strcpy(*field, tmp_text);
     }
   }
 }


Mime
View raw message