From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matan Azrad Subject: [PATCH v2] net/failsafe: fix parameters parsing Date: Sun, 20 Aug 2017 01:07:23 +0300 Message-ID: <1503180443-9687-1-git-send-email-matan@mellanox.com> References: Mime-Version: 1.0 Content-Type: text/plain Cc: dev@dpdk.org, stable@dpdk.org To: Gaetan Rivet Return-path: In-Reply-To: List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The corrupted code used wrongly snprintf return value as the number of characters actually copied, in spite of the meanning is the number of characters which would be generated for the given input. It caused to remain zerod bytes between the failsafe command line non sub device parameters indicates end of string. Hence, when rte_kvargs_parse tried to parse all parameters, it got end of string after the first one and the others weren't parsed. So, if the mac parameters was the first in command line it was taken while hotplug_poll was left default, and vice versa. The fix updates the buffer index by dedicated variable contains the copy size, by the way validates the last comma removing. Fixes: a46f8d584eb8 ("net/failsafe: add fail-safe PMD") Cc: stable@dpdk.org Signed-off-by: Matan Azrad --- drivers/net/failsafe/failsafe_args.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/net/failsafe/failsafe_args.c b/drivers/net/failsafe/failsafe_args.c index 1f22416..2a5760a 100644 --- a/drivers/net/failsafe/failsafe_args.c +++ b/drivers/net/failsafe/failsafe_args.c @@ -286,10 +286,14 @@ fs_remove_sub_devices_definition(char params[DEVARGS_MAXLEN]) ERROR("Invalid parameter"); return -EINVAL; } - if (params[b] == ',' || params[b] == '\0') - i += snprintf(&buffer[i], b - a + 1, "%s", ¶ms[a]); - if (params[b] == '(') { + if (params[b] == ',' || params[b] == '\0') { + size_t len = b - a + 1; + + snprintf(&buffer[i], len, "%s", ¶ms[a]); + i += len; + } else if (params[b] == '(') { size_t start = b; + b += closing_paren(¶ms[b]); if (b == start) return -EINVAL; @@ -300,6 +304,9 @@ fs_remove_sub_devices_definition(char params[DEVARGS_MAXLEN]) a = b + 1; } out: + if (i > 0) + /* For last comma preventing. */ + buffer[i - 1] = '\0'; snprintf(params, DEVARGS_MAXLEN, "%s", buffer); return 0; } -- 2.7.4