]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
util-ebpf: fix error reported by coccinelle check
authorEric Leblond <eric@regit.org>
Sun, 10 Mar 2019 10:53:22 +0000 (11:53 +0100)
committerVictor Julien <victor@inliniac.net>
Tue, 18 Jun 2019 05:07:02 +0000 (07:07 +0200)
Some allocation errors were not checked during init phase.

src/util-ebpf.c

index 4a5f25bd0a61f78e8836dc87818241b2f3b92ef0..38cd17905455a8e70a555f88e6b997a8d818644e 100644 (file)
@@ -215,8 +215,14 @@ static int EBPFLoadPinnedMaps(LiveDevice *livedev, struct ebpf_timeout_config *c
     if (config->mode == AFP_MODE_XDP_BYPASS) {
         bpf_map_data->array[0].fd = fd_v4;
         bpf_map_data->array[0].name = SCStrdup("flow_table_v4");
+        if (bpf_map_data->array[0].name == NULL) {
+            goto alloc_error;
+        }
         bpf_map_data->array[1].fd = fd_v6;
         bpf_map_data->array[1].name = SCStrdup("flow_table_v6");
+        if (bpf_map_data->array[1].name == NULL) {
+            goto alloc_error;
+        }
         bpf_map_data->last = 2;
     } else {
         bpf_map_data->last = 0;
@@ -227,24 +233,36 @@ static int EBPFLoadPinnedMaps(LiveDevice *livedev, struct ebpf_timeout_config *c
     if (fd >= 0) {
         bpf_map_data->array[bpf_map_data->last].fd = fd;
         bpf_map_data->array[bpf_map_data->last].name = SCStrdup("cpu_map");
+        if (bpf_map_data->array[bpf_map_data->last].name == NULL) {
+            goto alloc_error;
+        }
         bpf_map_data->last++;
     }
     fd = EBPFLoadPinnedMapsFile(livedev, "cpus_available");
     if (fd >= 0) {
         bpf_map_data->array[bpf_map_data->last].fd = fd;
         bpf_map_data->array[bpf_map_data->last].name = SCStrdup("cpus_available");
+        if (bpf_map_data->array[bpf_map_data->last].name == NULL) {
+            goto alloc_error;
+        }
         bpf_map_data->last++;
     }
     fd = EBPFLoadPinnedMapsFile(livedev, "tx_peer");
     if (fd >= 0) {
         bpf_map_data->array[bpf_map_data->last].fd = fd;
         bpf_map_data->array[bpf_map_data->last].name = SCStrdup("tx_peer");
+        if (bpf_map_data->array[bpf_map_data->last].name == NULL) {
+            goto alloc_error;
+        }
         bpf_map_data->last++;
     }
     fd = EBPFLoadPinnedMapsFile(livedev, "tx_peer_int");
     if (fd >= 0) {
         bpf_map_data->array[bpf_map_data->last].fd = fd;
         bpf_map_data->array[bpf_map_data->last].name = SCStrdup("tx_peer_int");
+        if (bpf_map_data->array[bpf_map_data->last].name == NULL) {
+            goto alloc_error;
+        }
         bpf_map_data->last++;
     }
 
@@ -252,6 +270,14 @@ static int EBPFLoadPinnedMaps(LiveDevice *livedev, struct ebpf_timeout_config *c
     LiveDevSetStorageById(livedev, g_livedev_storage_id, bpf_map_data);
 
     return 0;
+
+alloc_error:
+    for (int i = 0; i < bpf_map_data->last; i++) {
+        SCFree(bpf_map_data->array[i].name);
+    }
+    bpf_map_data->last = 0;
+    SCLogError(SC_ERR_MEM_ALLOC, "Can't allocate bpf map name");
+    return -1;
 }
 
 /**