Skip to contentSkip to conversation

ip: error out if iplink does not consume all options

PATCH Superseded Jakub Kicinski 2 participants 2 messages Jul 28, 2023 – Jul 30, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

PATCH 1/1 ip: error out if iplink does not consume all options

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".
---
 ip/iplink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
ip/iplink.c +1 -1
index 6c5d13d53a84..f60cff9c4b5f 100644
@@ -1112,7 +1112,7 @@ 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);
Signature · 1 line
2.41.0
#1 lore raw
Quoted 5 lines · On Fri, 28 Jul 2023 11:33:29 -0700 Jakub Kicinski <[email protected]> wrote:

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
Quoted 7 lines

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".

Looks good, but then the latter check for lu->parse_opt in the if clause is redundant. Coverity would flag that (assuming I get Coverity running again on iproute).