From 1df97980774c61fa20166992ecb220ceefa2d888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Svensson?= Date: Fri, 11 Feb 2022 16:09:03 +0100 Subject: [PATCH 1/3] Correcting check of config value for vip_addr6 Updated for code consistency, but checking the IPv4 vip_addr pointer might have given problems for IPv6 only configs. --- lib/ff_config.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ff_config.c b/lib/ff_config.c index 4d9269d81..afba0a15c 100644 --- a/lib/ff_config.c +++ b/lib/ff_config.c @@ -521,8 +521,8 @@ port_cfg_handler(struct ff_config *cfg, const char *section, cur->gateway6_str = strdup(value); } else if (strcmp(name, "vip_addr6") == 0) { cur->vip_addr6_str = strdup(value); - if (cur->vip_addr_str) { - return vip6_cfg_hander(cur); + if (cur->vip_addr6_str) { + return vip6_cfg_handler(cur); } } else if (0 == strcmp(name, "vip_prefix_len")) { cur->vip_prefix_len = atoi(value); From 2445361818bc839a4f784de80e4564a624fc31f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Svensson?= Date: Fri, 11 Feb 2022 16:24:45 +0100 Subject: [PATCH 2/3] Renaming vip6_cfg_hander() to vip6_cfg_handler() Corrected the output of an error log as well. --- lib/ff_config.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/ff_config.c b/lib/ff_config.c index afba0a15c..ed9de2ba3 100644 --- a/lib/ff_config.c +++ b/lib/ff_config.c @@ -367,7 +367,7 @@ parse_port_slave_list(struct ff_port_cfg *cfg, const char *v_str) } static int -vip_cfg_hander(struct ff_port_cfg *cur) +vip_cfg_handler(struct ff_port_cfg *cur) { //vip cfg int ret; @@ -375,7 +375,7 @@ vip_cfg_hander(struct ff_port_cfg *cur) ret = rte_strsplit(cur->vip_addr_str, strlen(cur->vip_addr_str), &vip_addr_array[0], VIP_MAX_NUM, ';'); if (ret <= 0) { - fprintf(stdout, "vip_cfg_hander nb_vip is 0, not set vip_addr or set invalid vip_addr %s\n", + fprintf(stdout, "vip_cfg_handler nb_vip is 0, not set vip_addr or set invalid vip_addr %s\n", cur->vip_addr_str); return 1; } @@ -384,7 +384,7 @@ vip_cfg_hander(struct ff_port_cfg *cur) cur->vip_addr_array = (char **)calloc(cur->nb_vip, sizeof(char *)); if (cur->vip_addr_array == NULL) { - fprintf(stderr, "vip_cfg_hander malloc failed\n"); + fprintf(stderr, "vip_cfg_handler malloc failed\n"); goto err; } @@ -404,7 +404,7 @@ err: #ifdef INET6 static int -vip6_cfg_hander(struct ff_port_cfg *cur) +vip6_cfg_handler(struct ff_port_cfg *cur) { //vip6 cfg int ret; @@ -413,7 +413,7 @@ vip6_cfg_hander(struct ff_port_cfg *cur) ret = rte_strsplit(cur->vip_addr6_str, strlen(cur->vip_addr6_str), &vip_addr6_array[0], VIP_MAX_NUM, ';'); if (ret == 0) { - fprintf(stdout, "vip6_cfg_hander nb_vip6 is 0, not set vip_addr6 or set invalid vip_addr6 %s\n", + fprintf(stdout, "vip6_cfg_handler nb_vip6 is 0, not set vip_addr6 or set invalid vip_addr6 %s\n", cur->vip_addr6_str); return 1; } @@ -422,7 +422,7 @@ vip6_cfg_hander(struct ff_port_cfg *cur) cur->vip_addr6_array = (char **) calloc(cur->nb_vip6, sizeof(char *)); if (cur->vip_addr6_array == NULL) { - fprintf(stderr, "port_cfg_handler malloc failed\n"); + fprintf(stderr, "vip6_cfg_handler malloc failed\n"); goto fail; } @@ -506,7 +506,7 @@ port_cfg_handler(struct ff_config *cfg, const char *section, } else if (strcmp(name, "vip_addr") == 0) { cur->vip_addr_str = strdup(value); if (cur->vip_addr_str) { - return vip_cfg_hander(cur); + return vip_cfg_handler(cur); } } else if (strcmp(name, "vip_ifname") == 0) { cur->vip_ifname = strdup(value); From 24a9ac33419d4cb2dcfc474af9b5ec7ce3f4fddb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Svensson?= Date: Fri, 11 Feb 2022 16:26:02 +0100 Subject: [PATCH 3/3] Avoid leaks after errors in freebsd config handler Freeing allocated memory in an error flow. Currently this would most likely not occure but a safeguard for future changes. --- lib/ff_config.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/ff_config.c b/lib/ff_config.c index ed9de2ba3..441b46c4e 100644 --- a/lib/ff_config.c +++ b/lib/ff_config.c @@ -191,6 +191,7 @@ freebsd_conf_handler(struct ff_config *cfg, const char *section, } } else { fprintf(stderr, "freebsd conf section[%s] error\n", section); + free(newconf); return 0; }