svn commit: r281326 - in stable: 10/sbin/ifconfig 9/sbin/ifconfig

John Baldwin jhb at FreeBSD.org
Thu Apr 9 21:06:53 UTC 2015


Author: jhb
Date: Thu Apr  9 21:06:51 2015
New Revision: 281326
URL: https://svnweb.freebsd.org/changeset/base/281326

Log:
  MFC 279951:
  Simplify string mangling in ifmaybeload().
  - Use strlcpy() instead of strcpy().
  - Use strlcat() instead of a strlcpy() with a magic number subtracted
    from the length.
  - Replace strncmp(..., strlen(foo) + 1) with strcmp(...).

Modified:
  stable/9/sbin/ifconfig/ifconfig.c
Directory Properties:
  stable/9/sbin/ifconfig/   (props changed)

Changes in other areas also in this revision:
Modified:
  stable/10/sbin/ifconfig/ifconfig.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/9/sbin/ifconfig/ifconfig.c
==============================================================================
--- stable/9/sbin/ifconfig/ifconfig.c	Thu Apr  9 21:05:48 2015	(r281325)
+++ stable/9/sbin/ifconfig/ifconfig.c	Thu Apr  9 21:06:51 2015	(r281326)
@@ -1100,9 +1100,8 @@ ifmaybeload(const char *name)
 		}
 
 	/* turn interface and unit into module name */
-	strcpy(ifkind, "if_");
-	strlcpy(ifkind + MOD_PREFIX_LEN, ifname,
-	    sizeof(ifkind) - MOD_PREFIX_LEN);
+	strlcpy(ifkind, "if_", sizeof(ifkind));
+	strlcat(ifkind, ifname, sizeof(ifkind));
 
 	/* scan files in kernel */
 	mstat.version = sizeof(struct module_stat);
@@ -1119,8 +1118,8 @@ ifmaybeload(const char *name)
 				cp = mstat.name;
 			}
 			/* already loaded? */
-			if (strncmp(ifname, cp, strlen(ifname) + 1) == 0 ||
-			    strncmp(ifkind, cp, strlen(ifkind) + 1) == 0)
+			if (strcmp(ifname, cp) == 0 ||
+			    strcmp(ifkind, cp) == 0)
 				return;
 		}
 	}


More information about the svn-src-stable-9 mailing list