Author: kib
Date: Mon Nov  2 21:47:34 2020
New Revision: 367285
URL: https://svnweb.freebsd.org/changeset/base/367285

Log:
  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

Modified:
  head/sbin/ifconfig/ifmedia.c

Modified: head/sbin/ifconfig/ifmedia.c
==============================================================================
--- head/sbin/ifconfig/ifmedia.c        Mon Nov  2 21:10:49 2020        
(r367284)
+++ head/sbin/ifconfig/ifmedia.c        Mon Nov  2 21:47:34 2020        
(r367285)
@@ -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;
        }
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to