]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ip: error out if iplink does not consume all options
authorJakub Kicinski <kuba@kernel.org>
Mon, 31 Jul 2023 16:19:20 +0000 (09:19 -0700)
committerStephen Hemminger <stephen@networkplumber.org>
Mon, 31 Jul 2023 16:56:44 +0000 (09:56 -0700)
dummy does not define .parse_opt, which make ip ignore all
trailing arguments, for example:

 # ip link add type dummy a b c d e f name cheese

will work just fine (and won't call the device "cheese").
Error out in this case with a clear error message:

 # ip link add type dummy a b c d e f name cheese
 Garbage instead of arguments "a ...". Try "ip link help".

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
ip/iplink.c

index 6c5d13d53a843a975bc30c6b95e754a18a7bd7d2..9a548dd35f54bcfef81ca8ae74d7702227bf437e 100644 (file)
@@ -1112,13 +1112,12 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
                argc -= ret;
                argv += ret;
 
-               if (lu && argc) {
+               if (lu && lu->parse_opt && argc) {
                        struct rtattr *data;
 
                        data = addattr_nest(&req.n, sizeof(req), iflatype);
 
-                       if (lu->parse_opt &&
-                           lu->parse_opt(lu, argc, argv, &req.n))
+                       if (lu->parse_opt(lu, argc, argv, &req.n))
                                return -1;
 
                        addattr_nest_end(&req.n, data);