Sat Oct 5 23:35:57 2019 UTC ()
use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.


(mrg)
diff -r1.70 -r1.71 src/usr.bin/make/arch.c
diff -r1.20 -r1.21 src/usr.bin/who/utmpentry.c

cvs diff -r1.70 -r1.71 src/usr.bin/make/arch.c (expand / switch to unified diff)

--- src/usr.bin/make/arch.c 2017/04/16 20:49:09 1.70
+++ src/usr.bin/make/arch.c 2019/10/05 23:35:57 1.71
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: arch.c,v 1.70 2017/04/16 20:49:09 riastradh Exp $ */ 1/* $NetBSD: arch.c,v 1.71 2019/10/05 23:35:57 mrg Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1989, 1990, 1993 4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor. 8 * Adam de Boor.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -59,34 +59,34 @@ @@ -59,34 +59,34 @@
59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 * SUCH DAMAGE. 68 * SUCH DAMAGE.
69 */ 69 */
70 70
71#ifndef MAKE_NATIVE 71#ifndef MAKE_NATIVE
72static char rcsid[] = "$NetBSD: arch.c,v 1.70 2017/04/16 20:49:09 riastradh Exp $"; 72static char rcsid[] = "$NetBSD: arch.c,v 1.71 2019/10/05 23:35:57 mrg Exp $";
73#else 73#else
74#include <sys/cdefs.h> 74#include <sys/cdefs.h>
75#ifndef lint 75#ifndef lint
76#if 0 76#if 0
77static char sccsid[] = "@(#)arch.c 8.2 (Berkeley) 1/2/94"; 77static char sccsid[] = "@(#)arch.c 8.2 (Berkeley) 1/2/94";
78#else 78#else
79__RCSID("$NetBSD: arch.c,v 1.70 2017/04/16 20:49:09 riastradh Exp $"); 79__RCSID("$NetBSD: arch.c,v 1.71 2019/10/05 23:35:57 mrg Exp $");
80#endif 80#endif
81#endif /* not lint */ 81#endif /* not lint */
82#endif 82#endif
83 83
84/*- 84/*-
85 * arch.c -- 85 * arch.c --
86 * Functions to manipulate libraries, archives and their members. 86 * Functions to manipulate libraries, archives and their members.
87 * 87 *
88 * Once again, cacheing/hashing comes into play in the manipulation 88 * Once again, cacheing/hashing comes into play in the manipulation
89 * of archives. The first time an archive is referenced, all of its members' 89 * of archives. The first time an archive is referenced, all of its members'
90 * headers are read and hashed and the archive closed again. All hashed 90 * headers are read and hashed and the archive closed again. All hashed
91 * archives are kept on a list which is searched each time an archive member 91 * archives are kept on a list which is searched each time an archive member
92 * is referenced. 92 * is referenced.
@@ -625,27 +625,27 @@ ArchStatMember(char *archive, char *memb @@ -625,27 +625,27 @@ ArchStatMember(char *archive, char *memb
625 * and there's no way we can recover... 625 * and there's no way we can recover...
626 */ 626 */
627 goto badarch; 627 goto badarch;
628 } else { 628 } else {
629 /* 629 /*
630 * We need to advance the stream's pointer to the start of the 630 * We need to advance the stream's pointer to the start of the
631 * next header. Files are padded with newlines to an even-byte 631 * next header. Files are padded with newlines to an even-byte
632 * boundary, so we need to extract the size of the file from the 632 * boundary, so we need to extract the size of the file from the
633 * 'size' field of the header and round it up during the seek. 633 * 'size' field of the header and round it up during the seek.
634 */ 634 */
635 arh.ar_size[sizeof(arh.ar_size)-1] = '\0'; 635 arh.ar_size[sizeof(arh.ar_size)-1] = '\0';
636 size = (int)strtol(arh.ar_size, NULL, 10); 636 size = (int)strtol(arh.ar_size, NULL, 10);
637 637
638 (void)strncpy(memName, arh.ar_name, sizeof(arh.ar_name)); 638 memcpy(memName, arh.ar_name, sizeof(arh.ar_name));
639 for (cp = &memName[AR_MAX_NAME_LEN]; *cp == ' '; cp--) { 639 for (cp = &memName[AR_MAX_NAME_LEN]; *cp == ' '; cp--) {
640 continue; 640 continue;
641 } 641 }
642 cp[1] = '\0'; 642 cp[1] = '\0';
643 643
644#ifdef SVR4ARCHIVES 644#ifdef SVR4ARCHIVES
645 /* 645 /*
646 * svr4 names are slash terminated. Also svr4 extended AR format. 646 * svr4 names are slash terminated. Also svr4 extended AR format.
647 */ 647 */
648 if (memName[0] == '/') { 648 if (memName[0] == '/') {
649 /* 649 /*
650 * svr4 magic mode; handle it 650 * svr4 magic mode; handle it
651 */ 651 */

cvs diff -r1.20 -r1.21 src/usr.bin/who/utmpentry.c (expand / switch to unified diff)

--- src/usr.bin/who/utmpentry.c 2019/10/04 11:43:07 1.20
+++ src/usr.bin/who/utmpentry.c 2019/10/05 23:35:57 1.21
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: utmpentry.c,v 1.20 2019/10/04 11:43:07 mrg Exp $ */ 1/* $NetBSD: utmpentry.c,v 1.21 2019/10/05 23:35:57 mrg Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2002 The NetBSD Foundation, Inc. 4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas. 8 * by Christos Zoulas.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -21,27 +21,27 @@ @@ -21,27 +21,27 @@
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#ifndef lint 33#ifndef lint
34__RCSID("$NetBSD: utmpentry.c,v 1.20 2019/10/04 11:43:07 mrg Exp $"); 34__RCSID("$NetBSD: utmpentry.c,v 1.21 2019/10/05 23:35:57 mrg Exp $");
35#endif 35#endif
36 36
37#include <sys/stat.h> 37#include <sys/stat.h>
38 38
39#include <time.h> 39#include <time.h>
40#include <string.h> 40#include <string.h>
41#include <err.h> 41#include <err.h>
42#include <stdlib.h> 42#include <stdlib.h>
43 43
44#ifdef SUPPORT_UTMP 44#ifdef SUPPORT_UTMP
45#include <utmp.h> 45#include <utmp.h>
46#endif 46#endif
47#ifdef SUPPORT_UTMPX 47#ifdef SUPPORT_UTMPX
@@ -268,62 +268,62 @@ getutentries(const char *fname, struct u @@ -268,62 +268,62 @@ getutentries(const char *fname, struct u
268} 268}
269 269
270#ifdef SUPPORT_UTMP 270#ifdef SUPPORT_UTMP
271static void 271static void
272getentry(struct utmpentry *e, struct utmp *up) 272getentry(struct utmpentry *e, struct utmp *up)
273{ 273{
274 COMPILE_ASSERT(sizeof(e->name) > sizeof(up->ut_name)); 274 COMPILE_ASSERT(sizeof(e->name) > sizeof(up->ut_name));
275 COMPILE_ASSERT(sizeof(e->line) > sizeof(up->ut_line)); 275 COMPILE_ASSERT(sizeof(e->line) > sizeof(up->ut_line));
276 COMPILE_ASSERT(sizeof(e->host) > sizeof(up->ut_host)); 276 COMPILE_ASSERT(sizeof(e->host) > sizeof(up->ut_host));
277 277
278 /* 278 /*
279 * e has just been calloc'd. We don't need to clear it or 279 * e has just been calloc'd. We don't need to clear it or
280 * append null-terminators, because its length is strictly 280 * append null-terminators, because its length is strictly
281 * greater than the source string. Use strncpy to _read_ 281 * greater than the source string. Use memcpy to _read_
282 * up->ut_* because they may not be terminated. For this 282 * up->ut_* because they may not be terminated. For this
283 * reason we use the size of the _source_ as the length 283 * reason we use the size of the _source_ as the length
284 * argument. 284 * argument.
285 */ 285 */
286 (void)strncpy(e->name, up->ut_name, sizeof(up->ut_name)); 286 memcpy(e->name, up->ut_name, sizeof(up->ut_name));
287 (void)strncpy(e->line, up->ut_line, sizeof(up->ut_line)); 287 memcpy(e->line, up->ut_line, sizeof(up->ut_line));
288 (void)strncpy(e->host, up->ut_host, sizeof(up->ut_host)); 288 memcpy(e->host, up->ut_host, sizeof(up->ut_host));
289 289
290 e->tv.tv_sec = up->ut_time; 290 e->tv.tv_sec = up->ut_time;
291 e->tv.tv_usec = 0; 291 e->tv.tv_usec = 0;
292 e->pid = 0; 292 e->pid = 0;
293 e->term = 0; 293 e->term = 0;
294 e->exit = 0; 294 e->exit = 0;
295 e->sess = 0; 295 e->sess = 0;
296 e->type = USER_PROCESS; 296 e->type = USER_PROCESS;
297 adjust_size(e); 297 adjust_size(e);
298} 298}
299#endif 299#endif
300 300
301#ifdef SUPPORT_UTMPX 301#ifdef SUPPORT_UTMPX
302static void 302static void
303getentryx(struct utmpentry *e, struct utmpx *up) 303getentryx(struct utmpentry *e, struct utmpx *up)
304{ 304{
305 COMPILE_ASSERT(sizeof(e->name) > sizeof(up->ut_name)); 305 COMPILE_ASSERT(sizeof(e->name) > sizeof(up->ut_name));
306 COMPILE_ASSERT(sizeof(e->line) > sizeof(up->ut_line)); 306 COMPILE_ASSERT(sizeof(e->line) > sizeof(up->ut_line));
307 COMPILE_ASSERT(sizeof(e->host) > sizeof(up->ut_host)); 307 COMPILE_ASSERT(sizeof(e->host) > sizeof(up->ut_host));
308 308
309 /* 309 /*
310 * e has just been calloc'd. We don't need to clear it or 310 * e has just been calloc'd. We don't need to clear it or
311 * append null-terminators, because its length is strictly 311 * append null-terminators, because its length is strictly
312 * greater than the source string. Use strncpy to _read_ 312 * greater than the source string. Use memcpy to _read_
313 * up->ut_* because they may not be terminated. For this 313 * up->ut_* because they may not be terminated. For this
314 * reason we use the size of the _source_ as the length 314 * reason we use the size of the _source_ as the length
315 * argument. 315 * argument.
316 */ 316 */
317 (void)strncpy(e->name, up->ut_name, sizeof(up->ut_name)); 317 memcpy(e->name, up->ut_name, sizeof(up->ut_name));
318 (void)strncpy(e->line, up->ut_line, sizeof(up->ut_line)); 318 memcpy(e->line, up->ut_line, sizeof(up->ut_line));
319 (void)strncpy(e->host, up->ut_host, sizeof(up->ut_host)); 319 memcpy(e->host, up->ut_host, sizeof(up->ut_host));
320 320
321 e->tv = up->ut_tv; 321 e->tv = up->ut_tv;
322 e->pid = up->ut_pid; 322 e->pid = up->ut_pid;
323 e->term = up->ut_exit.e_termination; 323 e->term = up->ut_exit.e_termination;
324 e->exit = up->ut_exit.e_exit; 324 e->exit = up->ut_exit.e_exit;
325 e->sess = up->ut_session; 325 e->sess = up->ut_session;
326 e->type = up->ut_type; 326 e->type = up->ut_type;
327 adjust_size(e); 327 adjust_size(e);
328} 328}
329#endif 329#endif