]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
eve: do not access flow storage in packet context 5555/head
authorSascha Steinbiss <satta@debian.org>
Sun, 8 Nov 2020 12:08:28 +0000 (13:08 +0100)
committerVictor Julien <victor@inliniac.net>
Wed, 11 Nov 2020 11:25:35 +0000 (12:25 +0100)
We must make sure not to access the flow storage (e.g. keeping a
MacSet) before making sure we have a flow to begin with, We can,
for example, run into an alert without a flow with `ip` rules,
in which case the flow might be NULL. See Redmine issue #4109.

src/output-json.c

index 7e55ba0385a541fdddd9ad5130dcb186c5766b9a..ce7250b75c6317a61ea4df738d972755c6038a18 100644 (file)
@@ -439,7 +439,7 @@ static void EveAddMetadata(const Packet *p, const Flow *f, JsonBuilder *js)
     }
 }
 
-int CreateJSONEther(JsonBuilder *parent, const Packet *p, const MacSet *ms);
+int CreateJSONEther(JsonBuilder *parent, const Packet *p, const Flow *f);
 
 void EveAddCommonOptions(const OutputJsonCommonSettings *cfg,
         const Packet *p, const Flow *f, JsonBuilder *js)
@@ -448,9 +448,7 @@ void EveAddCommonOptions(const OutputJsonCommonSettings *cfg,
         EveAddMetadata(p, f, js);
     }
     if (cfg->include_ethernet) {
-        MacSet *ms = FlowGetStorageById((Flow*) f, MacSetGetFlowStorageID());
-        if (ms != NULL)
-            CreateJSONEther(js, p, ms);
+        CreateJSONEther(js, p, f);
     }
     if (cfg->include_community_id && f != NULL) {
         CreateEveCommunityFlowId(js, f, cfg->community_id_seed);
@@ -798,15 +796,23 @@ static int MacSetIterateToJSON(uint8_t *val, MacSetSide side, void *data)
     return 0;
 }
 
-int CreateJSONEther(JsonBuilder *js, const Packet *p, const MacSet *ms)
+int CreateJSONEther(JsonBuilder *js, const Packet *p, const Flow *f)
 {
-    jb_open_object(js, "ether");
     if (unlikely(js == NULL))
         return 0;
+    /* start new EVE sub-object */
+    jb_open_object(js, "ether");
     if (p == NULL) {
+        MacSet *ms = NULL;
+        /* ensure we have a flow */
+        if (unlikely(f == NULL)) {
+            jb_close(js);
+            return 0;
+        }
         /* we are creating an ether object in a flow context, so we need to
            append to arrays */
-        if (MacSetSize(ms) > 0) {
+        ms = FlowGetStorageById((Flow *)f, MacSetGetFlowStorageID());
+        if (ms != NULL && MacSetSize(ms) > 0) {
             JSONMACAddrInfo info;
             info.dst = jb_new_array();
             info.src = jb_new_array();
@@ -815,6 +821,7 @@ int CreateJSONEther(JsonBuilder *js, const Packet *p, const MacSet *ms)
                 /* should not happen, JSONFlowAppendMACAddrs is sane */
                 jb_free(info.dst);
                 jb_free(info.src);
+                jb_close(js);
                 return ret;
             }
             jb_close(info.dst);