Module Name:    src
Committed By:   mrg
Date:           Sat Oct  5 23:35:57 UTC 2019

Modified Files:
        src/usr.bin/make: arch.c
        src/usr.bin/who: utmpentry.c

Log Message:
use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


To generate a diff of this commit:
cvs rdiff -u -r1.70 -r1.71 src/usr.bin/make/arch.c
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/who/utmpentry.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/arch.c
diff -u src/usr.bin/make/arch.c:1.70 src/usr.bin/make/arch.c:1.71
--- src/usr.bin/make/arch.c:1.70	Sun Apr 16 20:49:09 2017
+++ src/usr.bin/make/arch.c	Sat Oct  5 23:35:57 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: arch.c,v 1.70 2017/04/16 20:49:09 riastradh Exp $	*/
+/*	$NetBSD: arch.c,v 1.71 2019/10/05 23:35:57 mrg Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: arch.c,v 1.70 2017/04/16 20:49:09 riastradh Exp $";
+static char rcsid[] = "$NetBSD: arch.c,v 1.71 2019/10/05 23:35:57 mrg Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)arch.c	8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: arch.c,v 1.70 2017/04/16 20:49:09 riastradh Exp $");
+__RCSID("$NetBSD: arch.c,v 1.71 2019/10/05 23:35:57 mrg Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -635,7 +635,7 @@ ArchStatMember(char *archive, char *memb
 	    arh.ar_size[sizeof(arh.ar_size)-1] = '\0';
 	    size = (int)strtol(arh.ar_size, NULL, 10);
 
-	    (void)strncpy(memName, arh.ar_name, sizeof(arh.ar_name));
+	    memcpy(memName, arh.ar_name, sizeof(arh.ar_name));
 	    for (cp = &memName[AR_MAX_NAME_LEN]; *cp == ' '; cp--) {
 		continue;
 	    }

Index: src/usr.bin/who/utmpentry.c
diff -u src/usr.bin/who/utmpentry.c:1.20 src/usr.bin/who/utmpentry.c:1.21
--- src/usr.bin/who/utmpentry.c:1.20	Fri Oct  4 11:43:07 2019
+++ src/usr.bin/who/utmpentry.c	Sat Oct  5 23:35:57 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: utmpentry.c,v 1.20 2019/10/04 11:43:07 mrg Exp $	*/
+/*	$NetBSD: utmpentry.c,v 1.21 2019/10/05 23:35:57 mrg Exp $	*/
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: utmpentry.c,v 1.20 2019/10/04 11:43:07 mrg Exp $");
+__RCSID("$NetBSD: utmpentry.c,v 1.21 2019/10/05 23:35:57 mrg Exp $");
 #endif
 
 #include <sys/stat.h>
@@ -278,14 +278,14 @@ getentry(struct utmpentry *e, struct utm
 	/*
 	 * e has just been calloc'd. We don't need to clear it or
 	 * append null-terminators, because its length is strictly
-	 * greater than the source string. Use strncpy to _read_
+	 * greater than the source string. Use memcpy to _read_
 	 * up->ut_* because they may not be terminated. For this
 	 * reason we use the size of the _source_ as the length
 	 * argument.
 	 */
-	(void)strncpy(e->name, up->ut_name, sizeof(up->ut_name));
-	(void)strncpy(e->line, up->ut_line, sizeof(up->ut_line));
-	(void)strncpy(e->host, up->ut_host, sizeof(up->ut_host));
+	memcpy(e->name, up->ut_name, sizeof(up->ut_name));
+	memcpy(e->line, up->ut_line, sizeof(up->ut_line));
+	memcpy(e->host, up->ut_host, sizeof(up->ut_host));
 
 	e->tv.tv_sec = up->ut_time;
 	e->tv.tv_usec = 0;
@@ -309,14 +309,14 @@ getentryx(struct utmpentry *e, struct ut
 	/*
 	 * e has just been calloc'd. We don't need to clear it or
 	 * append null-terminators, because its length is strictly
-	 * greater than the source string. Use strncpy to _read_
+	 * greater than the source string. Use memcpy to _read_
 	 * up->ut_* because they may not be terminated. For this
 	 * reason we use the size of the _source_ as the length
 	 * argument.
 	 */
-	(void)strncpy(e->name, up->ut_name, sizeof(up->ut_name));
-	(void)strncpy(e->line, up->ut_line, sizeof(up->ut_line));
-	(void)strncpy(e->host, up->ut_host, sizeof(up->ut_host));
+	memcpy(e->name, up->ut_name, sizeof(up->ut_name));
+	memcpy(e->line, up->ut_line, sizeof(up->ut_line));
+	memcpy(e->host, up->ut_host, sizeof(up->ut_host));
 
 	e->tv = up->ut_tv;
 	e->pid = up->ut_pid;

Reply via email to