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@pmachata.org>
Signed-off-by: David Ahern <dsahern@gmail.com>
This commit is contained in:
Petr Machata 2020-11-12 23:24:45 +01:00 committed by David Ahern
parent 28e663ee65
commit bc3523ae70
1 changed files with 10 additions and 5 deletions

View File

@ -1770,6 +1770,7 @@ int parse_mapping(int *argcp, char ***argvp,
{ {
int argc = *argcp; int argc = *argcp;
char **argv = *argvp; char **argv = *argvp;
int ret = 0;
while (argc > 0) { while (argc > 0) {
char *colon = strchr(*argv, ':'); char *colon = strchr(*argv, ':');
@ -1779,15 +1780,19 @@ int parse_mapping(int *argcp, char ***argvp,
break; break;
*colon = '\0'; *colon = '\0';
if (get_u32(&key, *argv, 0)) if (get_u32(&key, *argv, 0)) {
return 1; ret = 1;
if (mapping_cb(key, colon + 1, mapping_cb_data)) break;
return 1; }
if (mapping_cb(key, colon + 1, mapping_cb_data)) {
ret = 1;
break;
}
argc--, argv++; argc--, argv++;
} }
*argcp = argc; *argcp = argc;
*argvp = argv; *argvp = argv;
return 0; return ret;
} }