]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
lib: parse_mapping: Update argc, argv on error
authorPetr Machata <me@pmachata.org>
Thu, 12 Nov 2020 22:24:45 +0000 (23:24 +0100)
committerDavid Ahern <dsahern@gmail.com>
Sat, 14 Nov 2020 02:43:15 +0000 (19:43 -0700)
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>
lib/utils.c

index 1dfaaf564915da6a2e8efdfb32ce2f0c3593e64a..67d64df7e3e6849d6da6d4e7e26e6e5846fc320d 100644 (file)
@@ -1770,6 +1770,7 @@ int parse_mapping(int *argcp, char ***argvp,
 {
        int argc = *argcp;
        char **argv = *argvp;
+       int ret = 0;
 
        while (argc > 0) {
                char *colon = strchr(*argv, ':');
@@ -1779,15 +1780,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;
 }