[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <4eaa2d34e2876a1901f4be565e21b482b9d55205.1604059429.git.me@pmachata.org>
Date: Fri, 30 Oct 2020 13:29:55 +0100
From: Petr Machata <me@...chata.org>
To: netdev@...r.kernel.org, dsahern@...il.com,
stephen@...workplumber.org
Cc: john.fastabend@...il.com, jiri@...dia.com, idosch@...dia.com,
Jakub Kicinski <kuba@...nel.org>,
Roman Mashak <mrv@...atatu.com>, Petr Machata <me@...chata.org>
Subject: [PATCH iproute2-next v2 08/11] lib: parse_mapping: Update argc, argv on error
Currently argc and argv are not updated unless parsing of all of the
mapping was successful. However in that case, "ip link" will point at the
wrong argument when complaining:
# ip link add name eth0.100 link eth0 type vlan id 100 egress 1:1 2:foo
Error: argument "1" is wrong: invalid egress-qos-map
Update argc and argv even in the case of parsing error, so that the right
element is indicated.
Signed-off-by: Petr Machata <me@...chata.org>
---
lib/utils.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/lib/utils.c b/lib/utils.c
index aba7cc0960cd..089bbde715da 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -1778,6 +1778,7 @@ int parse_mapping(int *argcp, char ***argvp,
{
int argc = *argcp;
char **argv = *argvp;
+ int ret = 0;
while (argc > 0) {
char *colon = strchr(*argv, ':');
@@ -1787,15 +1788,19 @@ int parse_mapping(int *argcp, char ***argvp,
break;
*colon = '\0';
- if (get_u32(&key, *argv, 0))
- return 1;
- if (mapping_cb(key, colon + 1, mapping_cb_data))
- return 1;
+ if (get_u32(&key, *argv, 0)) {
+ ret = 1;
+ break;
+ }
+ if (mapping_cb(key, colon + 1, mapping_cb_data)) {
+ ret = 1;
+ break;
+ }
argc--, argv++;
}
*argcp = argc;
*argvp = argv;
- return 0;
+ return ret;
}
--
2.25.1
Powered by blists - more mailing lists