Module Name: src
Committed By: riastradh
Date: Tue Jul 4 20:40:34 UTC 2023
Modified Files:
src/sbin/newfs: mkfs.c newfs.c
Log Message:
newfs(8): Ensure A divides S before aligned_alloc(A, S).
Required by C11 Sec. 7.22.3.1 The aligned_alloc function, para. 2,
p. 348:
The value of alignment shall be a valid alignment supported by the
implementation and the value of size shall be an integral multiple
of alignment.
XXX pullup-10
To generate a diff of this commit:
cvs rdiff -u -r1.133 -r1.134 src/sbin/newfs/mkfs.c
cvs rdiff -u -r1.118 -r1.119 src/sbin/newfs/newfs.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sbin/newfs/mkfs.c
diff -u src/sbin/newfs/mkfs.c:1.133 src/sbin/newfs/mkfs.c:1.134
--- src/sbin/newfs/mkfs.c:1.133 Sat Jan 7 19:41:29 2023
+++ src/sbin/newfs/mkfs.c Tue Jul 4 20:40:34 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: mkfs.c,v 1.133 2023/01/07 19:41:29 chs Exp $ */
+/* $NetBSD: mkfs.c,v 1.134 2023/07/04 20:40:34 riastradh Exp $ */
/*
* Copyright (c) 1980, 1989, 1993
@@ -73,7 +73,7 @@
#if 0
static char sccsid[] = "@(#)mkfs.c 8.11 (Berkeley) 5/3/95";
#else
-__RCSID("$NetBSD: mkfs.c,v 1.133 2023/01/07 19:41:29 chs Exp $");
+__RCSID("$NetBSD: mkfs.c,v 1.134 2023/07/04 20:40:34 riastradh Exp $");
#endif
#endif /* not lint */
@@ -201,9 +201,11 @@ mkfs(const char *fsys, int fi, int fo,
exit(12);
}
#endif
+ __CTASSERT((sizeof(*fsun) % DEV_BSIZE) == 0);
if ((fsun = aligned_alloc(DEV_BSIZE, sizeof(*fsun))) == NULL)
exit(12);
memset(fsun, 0, sizeof(*fsun));
+ __CTASSERT((sizeof(*cgun) % DEV_BSIZE) == 0);
if ((cgun = aligned_alloc(DEV_BSIZE, sizeof(*cgun))) == NULL)
exit(12);
memset(cgun, 0, sizeof(*cgun));
Index: src/sbin/newfs/newfs.c
diff -u src/sbin/newfs/newfs.c:1.118 src/sbin/newfs/newfs.c:1.119
--- src/sbin/newfs/newfs.c:1.118 Thu Nov 17 06:40:39 2022
+++ src/sbin/newfs/newfs.c Tue Jul 4 20:40:34 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: newfs.c,v 1.118 2022/11/17 06:40:39 chs Exp $ */
+/* $NetBSD: newfs.c,v 1.119 2023/07/04 20:40:34 riastradh Exp $ */
/*
* Copyright (c) 1983, 1989, 1993, 1994
@@ -78,7 +78,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 19
#if 0
static char sccsid[] = "@(#)newfs.c 8.13 (Berkeley) 5/1/95";
#else
-__RCSID("$NetBSD: newfs.c,v 1.118 2022/11/17 06:40:39 chs Exp $");
+__RCSID("$NetBSD: newfs.c,v 1.119 2023/07/04 20:40:34 riastradh Exp $");
#endif
#endif /* not lint */
@@ -624,7 +624,9 @@ main(int argc, char *argv[])
} else
bufsize = sfs.f_iosize;
- if ((buf = aligned_alloc(DEV_BSIZE, bufsize)) == NULL)
+ __CTASSERT(powerof2(DEV_BSIZE));
+ if ((buf = aligned_alloc(DEV_BSIZE,
+ roundup2(bufsize, DEV_BSIZE))) == NULL)
err(1, "can't malloc buffer of %d",
bufsize);
memset(buf, 0, bufsize);