From 3f113d56061ab4c877d837b0d683414d1303131a Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Mon, 2 Nov 2020 21:47:34 +0000 Subject: ifconfig: properly detect invalid mediaopt keywords. When invalid keyword is specified, ifconfig(8) is silent about it, instead random request is sent to the driver. Before the patch: root@r-freeb43:~ # ifconfig mce0 mediaopt -txpause,-rxpause ifconfig: SIOCSIFMEDIA (media): Device not configured After: root@r-freeb43:~ # ifconfig mce0 mediaopt -txpause,-rxpause ifconfig: unknown option: -txpause Reviewed by: hselasky, kp Sponsored by: Mellanox Technologies / NVidia Networking MFC after: 1 week Differential revision: https://reviews.freebsd.org/D27060 --- sbin/ifconfig/ifmedia.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'sbin/ifconfig') diff --git a/sbin/ifconfig/ifmedia.c b/sbin/ifconfig/ifmedia.c index fdf0d6fb62a0..cd3600df454c 100644 --- a/sbin/ifconfig/ifmedia.c +++ b/sbin/ifconfig/ifmedia.c @@ -566,7 +566,7 @@ get_media_options(int type, const char *val) struct ifmedia_description *desc; struct ifmedia_type_to_subtype *ttos; char *optlist, *optptr; - int option = 0, i, rval = 0; + int option, i, rval = 0; /* We muck with the string, so copy it. */ optlist = strdup(val); @@ -587,12 +587,13 @@ get_media_options(int type, const char *val) */ optptr = optlist; for (; (optptr = strtok(optptr, ",")) != NULL; optptr = NULL) { + option = -1; for (i = 0; ttos->options[i].desc != NULL; i++) { option = lookup_media_word(ttos->options[i].desc, optptr); if (option != -1) break; } - if (option == 0) + if (option == -1) errx(1, "unknown option: %s", optptr); rval |= option; } -- cgit v1.2.3