Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin/dump use strlcpy. use sizeof() instead of xxLEN to avo...
details: https://anonhg.NetBSD.org/src/rev/1a60e6e7fe33
branches: trunk
changeset: 539401:1a60e6e7fe33
user: itojun <itojun%NetBSD.org@localhost>
date: Sat Nov 16 14:15:35 2002 +0000
description:
use strlcpy. use sizeof() instead of xxLEN to avoid de-synchronization
diffstat:
sbin/dump/itime.c | 6 +++---
sbin/dump/main.c | 29 +++++++++++++++--------------
2 files changed, 18 insertions(+), 17 deletions(-)
diffs (91 lines):
diff -r 42dc250e165a -r 1a60e6e7fe33 sbin/dump/itime.c
--- a/sbin/dump/itime.c Sat Nov 16 14:09:16 2002 +0000
+++ b/sbin/dump/itime.c Sat Nov 16 14:15:35 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: itime.c,v 1.13 2001/12/25 12:06:26 lukem Exp $ */
+/* $NetBSD: itime.c,v 1.14 2002/11/16 14:15:35 itojun Exp $ */
/*-
* Copyright (c) 1980, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)itime.c 8.1 (Berkeley) 6/5/93";
#else
-__RCSID("$NetBSD: itime.c,v 1.13 2001/12/25 12:06:26 lukem Exp $");
+__RCSID("$NetBSD: itime.c,v 1.14 2002/11/16 14:15:35 itojun Exp $");
#endif
#endif /* not lint */
@@ -200,7 +200,7 @@
(struct dumpdates *)xcalloc(1, sizeof (struct dumpdates));
nddates += 1;
found:
- (void) strncpy(dtwalk->dd_name, fname, sizeof (dtwalk->dd_name));
+ (void) strlcpy(dtwalk->dd_name, fname, sizeof(dtwalk->dd_name));
dtwalk->dd_level = level;
dtwalk->dd_ddate = iswap32(spcl.c_date);
dtfound = dtwalk;
diff -r 42dc250e165a -r 1a60e6e7fe33 sbin/dump/main.c
--- a/sbin/dump/main.c Sat Nov 16 14:09:16 2002 +0000
+++ b/sbin/dump/main.c Sat Nov 16 14:15:35 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.50 2002/01/07 17:34:09 bouyer Exp $ */
+/* $NetBSD: main.c,v 1.51 2002/11/16 14:15:35 itojun Exp $ */
/*-
* Copyright (c) 1980, 1991, 1993, 1994
@@ -43,7 +43,7 @@
#if 0
static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 5/1/95";
#else
-__RCSID("$NetBSD: main.c,v 1.50 2002/01/07 17:34:09 bouyer Exp $");
+__RCSID("$NetBSD: main.c,v 1.51 2002/11/16 14:15:35 itojun Exp $");
#endif
#endif /* not lint */
@@ -202,12 +202,11 @@
* the last must be '\0', so the limit on strlen()
* is really LBLSIZE-1.
*/
- strncpy(labelstr, optarg, LBLSIZE);
- labelstr[LBLSIZE-1] = '\0';
- if (strlen(optarg) > LBLSIZE-1) {
+ if (strlcpy(labelstr, optarg, sizeof(labelstr))
+ >= sizeof(labelstr)) {
msg(
"WARNING Label `%s' is larger than limit of %d characters.\n",
- optarg, LBLSIZE-1);
+ optarg, sizeof(labelstr) - 1);
msg("WARNING: Using truncated label `%s'.\n",
labelstr);
}
@@ -402,19 +401,21 @@
}
if (mountpoint != NULL) {
if (dirc != 0)
- (void)snprintf(spcl.c_filesys, NAMELEN,
+ (void)snprintf(spcl.c_filesys, sizeof(spcl.c_filesys),
"a subset of %s", mountpoint);
else
- (void)strncpy(spcl.c_filesys, mountpoint, NAMELEN);
+ (void)strlcpy(spcl.c_filesys, mountpoint,
+ sizeof(spcl.c_filesys));
} else if (Fflag) {
- (void)strncpy(spcl.c_filesys, "a file system image", NAMELEN);
+ (void)strlcpy(spcl.c_filesys, "a file system image",
+ sizeof(spcl.c_filesys));
} else {
- (void)strncpy(spcl.c_filesys, "an unlisted file system",
- NAMELEN);
+ (void)strlcpy(spcl.c_filesys, "an unlisted file system",
+ sizeof(spcl.c_filesys));
}
- (void)strncpy(spcl.c_dev, disk, NAMELEN);
- (void)strncpy(spcl.c_label, labelstr, sizeof(spcl.c_label) - 1);
- (void)gethostname(spcl.c_host, NAMELEN);
+ (void)strlcpy(spcl.c_dev, disk, sizeof(spcl.c_dev));
+ (void)strlcpy(spcl.c_label, labelstr, sizeof(spcl.c_label));
+ (void)gethostname(spcl.c_host, sizeof(spcl.c_host));
spcl.c_host[sizeof(spcl.c_host) - 1] = '\0';
if ((diskfd = open(disk, O_RDONLY)) < 0) {
Home |
Main Index |
Thread Index |
Old Index