From 975549e01df338a90e1d1a356d22a2c7f5bf2387 Mon Sep 17 00:00:00 2001
From: Amin Ben Romdhane <amin.benromdhane@iopsys.eu>
Date: Thu, 19 Oct 2023 17:20:23 +0200
Subject: [PATCH] bbf_plugin: Fix a crash in the synchronize function
---
src/bbf_plugin/hosts.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/src/bbf_plugin/hosts.c b/src/bbf_plugin/hosts.c
index 01324b1..21a11b3 100644
--- a/src/bbf_plugin/hosts.c
+++ b/src/bbf_plugin/hosts.c
@@ -41,11 +41,16 @@ static int host_get_last_instance(void)
static void synchronize_hosts_array_with_dmmap(json_object *res)
{
struct uci_section *s = NULL, *stmp = NULL;
+ json_object *hosts_arr = NULL;
char *mac = NULL, *host_mac = NULL;
bool host_read_idx = false;
int host_idx = 0;
- size_t nbre_hosts = (res) ? json_object_array_length(res) : 0;
+ if (!res)
+ return;
+
+ json_object_object_get_ex(res, "hosts", &hosts_arr);
+ int nbre_hosts = (hosts_arr) ? json_object_array_length(hosts_arr) : 0;
uci_path_foreach_sections_safe(bbfdm, "dmmap_hosts", "host", stmp, s) {
@@ -53,7 +58,7 @@ static void synchronize_hosts_array_with_dmmap(json_object *res)
if (host_idx < nbre_hosts) {
if (!host_read_idx) {
- json_object *host_obj = json_object_array_get_idx(res, host_idx);
+ json_object *host_obj = json_object_array_get_idx(hosts_arr, host_idx);
host_mac = dmjson_get_value(host_obj, 1, "macaddr");
host_read_idx = true;
}
--
GitLab