svn commit: r355772 - in stable/12: libexec/getty sbin/ipfw

Xin LI delphij at FreeBSD.org
Sun Dec 15 08:23:39 UTC 2019


Author: delphij
Date: Sun Dec 15 08:23:38 2019
New Revision: 355772
URL: https://svnweb.freebsd.org/changeset/base/355772

Log:
  MFC r355222, r355260:
  
  r355222: Use strlcat().
  r355260: Simplify code with strlcpy/strlcat.

Modified:
  stable/12/libexec/getty/main.c
  stable/12/libexec/getty/subr.c
  stable/12/sbin/ipfw/dummynet.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/libexec/getty/main.c
==============================================================================
--- stable/12/libexec/getty/main.c	Sun Dec 15 06:26:47 2019	(r355771)
+++ stable/12/libexec/getty/main.c	Sun Dec 15 08:23:38 2019	(r355772)
@@ -97,7 +97,6 @@ static int crmod, digit, lower, upper;
 
 char	hostname[MAXHOSTNAMELEN];
 static char	name[MAXLOGNAME*3];
-static char	dev[] = _PATH_DEV;
 static char	ttyn[32];
 
 #define	OBUFSIZ		128
@@ -218,8 +217,8 @@ main(int argc, char *argv[])
 	if (argc <= 2 || strcmp(argv[2], "-") == 0)
 	    strcpy(ttyn, ttyname(STDIN_FILENO));
 	else {
-	    strcpy(ttyn, dev);
-	    strncat(ttyn, argv[2], sizeof(ttyn)-sizeof(dev));
+	    strcpy(ttyn, _PATH_DEV);
+	    strlcat(ttyn, argv[2], sizeof(ttyn));
 	    if (strcmp(argv[0], "+") != 0) {
 		chown(ttyn, 0, 0);
 		chmod(ttyn, 0600);

Modified: stable/12/libexec/getty/subr.c
==============================================================================
--- stable/12/libexec/getty/subr.c	Sun Dec 15 06:26:47 2019	(r355771)
+++ stable/12/libexec/getty/subr.c	Sun Dec 15 08:23:38 2019	(r355772)
@@ -89,10 +89,8 @@ gettable(const char *name, char *buf)
 					l = 2;
 				else
 					l = strlen(sp->value) + 1;
-				if ((p = malloc(l)) != NULL) {
-					strncpy(p, sp->value, l);
-					p[l-1] = '\0';
-				}
+				if ((p = malloc(l)) != NULL)
+					strlcpy(p, sp->value, l);
 				/*
 				 * replace, even if NULL, else we'll
 				 * have problems with free()ing static mem

Modified: stable/12/sbin/ipfw/dummynet.c
==============================================================================
--- stable/12/sbin/ipfw/dummynet.c	Sun Dec 15 06:26:47 2019	(r355771)
+++ stable/12/sbin/ipfw/dummynet.c	Sun Dec 15 08:23:38 2019	(r355772)
@@ -497,7 +497,7 @@ print_flowset_parms(struct dn_fs *fs, char *prefix)
 		    fs->max_th,
 		    1.0 * fs->max_p / (double)(1 << SCALE_RED));
 		if (fs->flags & DN_IS_ECN)
-			strncat(red, " (ecn)", 6);
+			strlcat(red, " (ecn)", sizeof(red));
 #ifdef NEW_AQM
 	/* get AQM parameters */
 	} else if (fs->flags & DN_IS_AQM) {


More information about the svn-src-all mailing list