Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 13 Mar 2015 09:45:07 +0000 (UTC)
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r279951 - head/sbin/ifconfig
Message-ID:  <201503130945.t2D9j7UT081560@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhb
Date: Fri Mar 13 09:45:06 2015
New Revision: 279951
URL: https://svnweb.freebsd.org/changeset/base/279951

Log:
  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(...).
  
  Differential Revision:	https://reviews.freebsd.org/D1814
  Reviewed by:	rpaulo
  MFC after:	2 weeks

Modified:
  head/sbin/ifconfig/ifconfig.c

Modified: head/sbin/ifconfig/ifconfig.c
==============================================================================
--- head/sbin/ifconfig/ifconfig.c	Fri Mar 13 09:41:27 2015	(r279950)
+++ head/sbin/ifconfig/ifconfig.c	Fri Mar 13 09:45:06 2015	(r279951)
@@ -1280,9 +1280,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);
@@ -1299,8 +1298,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;
 		}
 	}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201503130945.t2D9j7UT081560>