Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Add a function lfs_copydirname() to copy directory names in ...
details: https://anonhg.NetBSD.org/src/rev/937ce769ee6c
branches: trunk
changeset: 340590:937ce769ee6c
user: dholland <dholland%NetBSD.org@localhost>
date: Tue Sep 15 15:01:38 2015 +0000
description:
Add a function lfs_copydirname() to copy directory names in place; use
it in place of (variously) memcpy and strlcpy. (The latter isn't even
correct; was probably changed blindly from strncpy at some point.)
The new function zeroes the padding in the directory entry instead of
leaving trash behind.
diffstat:
sbin/fsck_lfs/dir.c | 7 +++++--
sbin/fsck_lfs/pass2.c | 14 +++++++-------
sbin/newfs_lfs/make_lfs.c | 13 ++++---------
sys/ufs/lfs/lfs_accessors.h | 13 ++++++++++++-
4 files changed, 28 insertions(+), 19 deletions(-)
diffs (138 lines):
diff -r f085127e52c3 -r 937ce769ee6c sbin/fsck_lfs/dir.c
--- a/sbin/fsck_lfs/dir.c Tue Sep 15 15:01:22 2015 +0000
+++ b/sbin/fsck_lfs/dir.c Tue Sep 15 15:01:38 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dir.c,v 1.40 2015/09/15 15:01:22 dholland Exp $ */
+/* $NetBSD: dir.c,v 1.41 2015/09/15 15:01:38 dholland Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@@ -198,6 +198,7 @@
lfs_dir_setnamlen(fs, dp, 0);
lfs_dir_setreclen(fs, dp, LFS_DIRBLKSIZ);
/* for now at least, don't zero the old contents */
+ /*lfs_copydirname(fs, dp->d_name, "", 0, LFS_DIRBLKSIZ);*/
dp->d_name[0] = '\0';
if (fix)
VOP_BWRITE(bp);
@@ -399,7 +400,9 @@
lfs_dir_setreclen(fs, dirp, newreclen);
lfs_dir_settype(fs, dirp, typemap[idesc->id_parent]);
lfs_dir_setnamlen(fs, dirp, namlen);
- memcpy(dirp->d_name, idesc->id_name, (size_t)namlen + 1);
+ lfs_copydirname(fs, dirp->d_name, idesc->id_name,
+ namlen, newreclen);
+
return (ALTERED | STOP);
}
diff -r f085127e52c3 -r 937ce769ee6c sbin/fsck_lfs/pass2.c
--- a/sbin/fsck_lfs/pass2.c Tue Sep 15 15:01:22 2015 +0000
+++ b/sbin/fsck_lfs/pass2.c Tue Sep 15 15:01:38 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pass2.c,v 1.29 2015/09/15 15:01:22 dholland Exp $ */
+/* $NetBSD: pass2.c,v 1.30 2015/09/15 15:01:38 dholland Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@@ -258,16 +258,16 @@
/* convert this entry to a . entry */
lfs_dir_setreclen(fs, &proto, lfs_dir_getreclen(fs, dirp));
memcpy(dirp, &proto, sizeof(proto));
- /* 4 is entrysize - headersize (XXX: clean up) */
- (void) strlcpy(dirp->d_name, ".", 4);
+ lfs_copydirname(fs, dirp->d_name, ".", 1,
+ lfs_dir_getreclen(fs, dirp));
if (reply("FIX") == 1)
ret |= ALTERED;
} else {
/* split this entry and use the beginning for the . entry */
n = lfs_dir_getreclen(fs, dirp) - entrysize;
memcpy(dirp, &proto, sizeof(proto));
- /* XXX see case above */
- (void) strlcpy(dirp->d_name, ".", 4);
+ lfs_copydirname(fs, dirp->d_name, ".", 1,
+ lfs_dir_getreclen(fs, dirp));
idesc->id_entryno++;
lncntp[lfs_dir_getino(fs, dirp)]--;
dirp = LFS_NEXTDIR(fs, dirp);
@@ -324,8 +324,8 @@
fileerror(inp->i_parent, idesc->id_number, "MISSING '..'");
lfs_dir_setreclen(fs, &proto, lfs_dir_getreclen(fs, dirp));
memcpy(dirp, &proto, (size_t) entrysize);
- /* 4 is entrysize - headersize (XXX: clean up) */
- (void) strlcpy(proto.d_name, "..", 4);
+ lfs_copydirname(fs, dirp->d_name, "..", 2,
+ lfs_dir_getreclen(fs, dirp));
if (reply("FIX") == 1)
ret |= ALTERED;
}
diff -r f085127e52c3 -r 937ce769ee6c sbin/newfs_lfs/make_lfs.c
--- a/sbin/newfs_lfs/make_lfs.c Tue Sep 15 15:01:22 2015 +0000
+++ b/sbin/newfs_lfs/make_lfs.c Tue Sep 15 15:01:38 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: make_lfs.c,v 1.51 2015/09/15 14:59:58 dholland Exp $ */
+/* $NetBSD: make_lfs.c,v 1.52 2015/09/15 15:01:38 dholland Exp $ */
/*-
* Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
#if 0
static char sccsid[] = "@(#)lfs.c 8.5 (Berkeley) 5/24/95";
#else
-__RCSID("$NetBSD: make_lfs.c,v 1.51 2015/09/15 14:59:58 dholland Exp $");
+__RCSID("$NetBSD: make_lfs.c,v 1.52 2015/09/15 15:01:38 dholland Exp $");
#endif
#endif /* not lint */
@@ -361,7 +361,6 @@
unsigned spaceleft;
unsigned namlen, reclen;
unsigned i;
- char *pad;
spaceleft = LFS_DIRBLKSIZ;
ep = bufp;
@@ -381,13 +380,9 @@
lfs_dir_setreclen(fs, ep, reclen);
lfs_dir_settype(fs, ep, protodir[i].dp_type);
lfs_dir_setnamlen(fs, ep, namlen);
- memcpy(ep->d_name, protodir[i].dp_name, namlen);
- pad = ep->d_name + namlen;
+ lfs_copydirname(fs, ep->d_name, protodir[i].dp_name,
+ namlen, reclen);
ep = LFS_NEXTDIR(fs, ep);
-
- while (pad < (char *)ep) {
- *pad++ = '\0';
- }
}
assert(spaceleft == 0);
}
diff -r f085127e52c3 -r 937ce769ee6c sys/ufs/lfs/lfs_accessors.h
--- a/sys/ufs/lfs/lfs_accessors.h Tue Sep 15 15:01:22 2015 +0000
+++ b/sys/ufs/lfs/lfs_accessors.h Tue Sep 15 15:01:38 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lfs_accessors.h,v 1.24 2015/09/15 14:59:58 dholland Exp $ */
+/* $NetBSD: lfs_accessors.h,v 1.25 2015/09/15 15:01:38 dholland Exp $ */
/* from NetBSD: lfs.h,v 1.165 2015/07/24 06:59:32 dholland Exp */
/* from NetBSD: dinode.h,v 1.22 2013/01/22 09:39:18 dholland Exp */
@@ -307,6 +307,17 @@
dp->d_header.dh_namlen = namlen;
}
+static __unused inline void
+lfs_copydirname(STRUCT_LFS *fs, char *dest, const char *src,
+ unsigned namlen, unsigned reclen)
+{
+ /* must always be at least 1 byte as a null terminator */
+ KASSERT(reclen > namlen);
+
+ memcpy(dest, src, namlen);
+ memset(dest + namlen, '\0', reclen - namlen);
+}
+
/*
* These are called "dirt" because they ought to be cleaned up.
*/
Home |
Main Index |
Thread Index |
Old Index