From c5e2af05459e809deba76547110248af8b73ced8 Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Sun, 10 Mar 2019 11:53:22 +0100 Subject: [PATCH] util-ebpf: fix error reported by coccinelle check Some allocation errors were not checked during init phase. --- src/util-ebpf.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/util-ebpf.c b/src/util-ebpf.c index 4a5f25bd0a..38cd179054 100644 --- a/src/util-ebpf.c +++ b/src/util-ebpf.c @@ -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; } /**