]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
email-json: delete leading white spaces
authorEric Leblond <eric@regit.org>
Mon, 4 May 2015 16:11:37 +0000 (18:11 +0200)
committerEric Leblond <eric@regit.org>
Tue, 6 Oct 2015 21:30:45 +0000 (23:30 +0200)
Some mail clients are using tabulation and/or space for comma
separated list. This patch removes them so the event will contain
only significative characters.

src/output-json-email-common.c

index d539308a9846c85ec8385a13eb835279bc7f26bd..533ce17ade4ca828d585a19da841cf33991816ed 100644 (file)
@@ -76,21 +76,41 @@ struct {
     { NULL, NULL, LOG_EMAIL_DEFAULT},
 };
 
+static inline char *SkipWhiteSpaceTill(char *p, char *savep)
+{
+    char *sp = p;
+    if (unlikely(p == NULL)) {
+        return NULL;
+    }
+    while (((*sp == '\t') || (*sp == ' ')) && (sp < savep)) {
+        sp++;
+    }
+    return sp;
+}
+
 static json_t* JsonEmailJsonArrayFromCommaList(const uint8_t *val, size_t len)
 {
     json_t *ajs = json_array();
     if (likely(ajs != NULL)) {
         char *savep = NULL;
         char *p;
+        char *sp;
         char *to_line = BytesToString((uint8_t *)val, len);
         if (likely(to_line != NULL)) {
             p = strtok_r(to_line, ",", &savep);
-            json_array_append_new(ajs, json_string(p));
+            if (p == NULL) {
+                json_decref(ajs);
+                SCFree(to_line);
+                return NULL;
+            }
+            sp = SkipWhiteSpaceTill(p, savep);
+            json_array_append_new(ajs, json_string(sp));
             while ((p = strtok_r(NULL, ",", &savep)) != NULL) {
-                json_array_append_new(ajs, json_string(&p[strspn(p, " ")]));
+                sp = SkipWhiteSpaceTill(p, savep);
+                json_array_append_new(ajs, json_string(sp));
             }
-            SCFree(to_line);
         }
+        SCFree(to_line);
     }
 
     return ajs;