From 2a0155c3994a546d53a17eecc6659bed6798e6c5 Mon Sep 17 00:00:00 2001 From: claudio Date: Fri, 17 Mar 2023 16:11:09 +0000 Subject: [PATCH] Adjust sourceaddr argument parser. Only print the sourceaddrs if no argument was passed. If arguemnts are set make sure that either and address is present or that an ifp was given. This make the command behave a more like other route commands. OK deraadt@ --- sbin/route/route.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/sbin/route/route.c b/sbin/route/route.c index 49b675f10b4..755e548e9cc 100644 --- a/sbin/route/route.c +++ b/sbin/route/route.c @@ -1,4 +1,4 @@ -/* $OpenBSD: route.c,v 1.264 2023/03/15 08:43:51 claudio Exp $ */ +/* $OpenBSD: route.c,v 1.265 2023/03/17 16:11:09 claudio Exp $ */ /* $NetBSD: route.c,v 1.16 1996/04/15 18:27:05 cgd Exp $ */ /* @@ -487,6 +487,10 @@ setsource(int argc, char **argv) unsigned int ifindex = 0; cmd = argv[0]; + + if (argc == 1) + printsource(AF_UNSPEC, tableid); + while (--argc > 0) { if (**(++argv)== '-') { switch (key = keyword(1 + *argv)) { @@ -505,14 +509,14 @@ setsource(int argc, char **argv) if (ifindex == 0) errx(1, "no such interface %s", *argv); break; + default: + usage(NULL); } } else break; } - if (argc <= 0 && ifindex == 0) - printsource(AF_UNSPEC, tableid); - if (argc > 1 && ifindex == 0) + if (!(argc == 1 && ifindex == 0) && !(argc == 0 && ifindex != 0)) usage(NULL); if (uid) -- 2.20.1