summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>1998-08-07 17:29:26 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>1998-08-07 17:29:26 +0000
commite35ef9b65068f5196a0b33c34106f6f49db38780 (patch)
tree036fadc5a8a77dc4f68952e055bcd824e6a1469e
parent53796aa2246dd1e12da7ecff86653af747b67da4 (diff)
Use strlcpy() instead of strncpy().
Change the order of name -> raw device conversions 1) statfs the name and use that info iff the name is the mount point 2) look up name in fstab 3) treat as a device The reason for this is that the mounted filesystems may not agree with what fstab says. Anyone who has ever moved disks around and accidentally dumped and empty filesystem will know what I mean.
-rw-r--r--sbin/dump/itime.c7
-rw-r--r--sbin/dump/main.c46
2 files changed, 26 insertions, 27 deletions
diff --git a/sbin/dump/itime.c b/sbin/dump/itime.c
index ba7682a243f..7d2ef2ede09 100644
--- a/sbin/dump/itime.c
+++ b/sbin/dump/itime.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: itime.c,v 1.4 1998/02/08 19:24:08 deraadt Exp $ */
+/* $OpenBSD: itime.c,v 1.5 1998/08/07 17:29:24 millert Exp $ */
/* $NetBSD: itime.c,v 1.4 1997/04/15 01:09:50 lukem Exp $ */
/*-
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)itime.c 8.1 (Berkeley) 6/5/93";
#else
-static char rcsid[] = "$OpenBSD: itime.c,v 1.4 1998/02/08 19:24:08 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: itime.c,v 1.5 1998/08/07 17:29:24 millert Exp $";
#endif
#endif /* not lint */
@@ -211,8 +211,7 @@ putdumptime()
(struct dumpdates *)calloc(1, sizeof(struct dumpdates));
nddates += 1;
found:
- (void) strncpy(dtwalk->dd_name, fname, sizeof(dtwalk->dd_name) - 1);
- dtwalk->dd_name[sizeof(dtwalk->dd_name) - 1] = '\0';
+ (void) strlcpy(dtwalk->dd_name, fname, sizeof(dtwalk->dd_name));
dtwalk->dd_level = level;
dtwalk->dd_ddate = spcl.c_date;
diff --git a/sbin/dump/main.c b/sbin/dump/main.c
index f57f5404241..270727983dc 100644
--- a/sbin/dump/main.c
+++ b/sbin/dump/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.20 1998/07/28 23:27:58 millert Exp $ */
+/* $OpenBSD: main.c,v 1.21 1998/08/07 17:29:25 millert Exp $ */
/* $NetBSD: main.c,v 1.14 1997/06/05 11:13:24 lukem Exp $ */
/*-
@@ -347,36 +347,36 @@ main(argc, argv)
* the special name missing the leading '/',
* the file system name with or without the leading '/'.
*/
- dt = fstabsearch(disk);
- if (dt != NULL) {
+ if (!statfs(disk, &fsbuf) && !strcmp(fsbuf.f_mntonname, disk)) {
+ /* mounted disk? */
+ disk = rawname(fsbuf.f_mntfromname);
+ (void)strlcpy(spcl.c_dev, fsbuf.f_mntfromname,
+ sizeof(spcl.c_dev));
+ if (dirlist != 0) {
+ (void)snprintf(spcl.c_filesys, sizeof(spcl.c_filesys),
+ "a subset of %s", fsbuf.f_mntonname);
+ } else {
+ (void)strlcpy(spcl.c_filesys, fsbuf.f_mntonname,
+ sizeof(spcl.c_filesys));
+ }
+ } else if ((dt = fstabsearch(disk)) != NULL) {
+ /* in fstab? */
disk = rawname(dt->fs_spec);
- (void)strncpy(spcl.c_dev, dt->fs_spec, sizeof(spcl.c_dev) - 1);
- spcl.c_dev[sizeof(spcl.c_dev) - 1] = '\0';
+ (void)strlcpy(spcl.c_dev, dt->fs_spec, sizeof(spcl.c_dev));
if (dirlist != 0) {
(void)snprintf(spcl.c_filesys, sizeof(spcl.c_filesys),
"a subset of %s", dt->fs_file);
} else {
- (void)strncpy(spcl.c_filesys, dt->fs_file,
- sizeof(spcl.c_filesys) - 1);
- spcl.c_filesys[sizeof(spcl.c_filesys) - 1] = '\0';
+ (void)strlcpy(spcl.c_filesys, dt->fs_file,
+ sizeof(spcl.c_filesys));
}
- } else if (!statfs(disk, &fsbuf) && !strcmp(fsbuf.f_mntonname, disk)) {
- disk = rawname(fsbuf.f_mntfromname);
- (void)strncpy(spcl.c_dev, fsbuf.f_mntfromname,
- sizeof(spcl.c_dev) - 1);
- spcl.c_dev[sizeof(spcl.c_dev) - 1] = '\0';
- (void)strncpy(spcl.c_filesys, fsbuf.f_mntonname,
- sizeof(spcl.c_filesys) - 1);
- spcl.c_filesys[sizeof(spcl.c_filesys) - 1] = '\0';
} else {
- (void)strncpy(spcl.c_dev, disk, sizeof(spcl.c_dev) - 1);
- spcl.c_dev[sizeof(spcl.c_dev) - 1] = '\0';
- (void)strncpy(spcl.c_filesys, "an unlisted file system",
- sizeof(spcl.c_filesys) - 1);
- spcl.c_filesys[sizeof(spcl.c_filesys) - 1] = '\0';
+ /* must be a device */
+ (void)strlcpy(spcl.c_dev, disk, sizeof(spcl.c_dev));
+ (void)strlcpy(spcl.c_filesys, "an unlisted file system",
+ sizeof(spcl.c_filesys));
}
- (void)strncpy(spcl.c_label, "none", sizeof(spcl.c_label) - 1);
- spcl.c_label[sizeof(spcl.c_label) - 1] = '\0';
+ (void)strlcpy(spcl.c_label, "none", sizeof(spcl.c_label));
(void)gethostname(spcl.c_host, sizeof(spcl.c_host));
spcl.c_level = level - '0';
spcl.c_type = TS_TAPE;