Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin/fsck_ffs fsck_ffs(8): Ensure A divides S before aligned...
details: https://anonhg.NetBSD.org/src/rev/05b3b074ab1c
branches: trunk
changeset: 377266:05b3b074ab1c
user: riastradh <riastradh%NetBSD.org@localhost>
date: Tue Jul 04 20:40:22 2023 +0000
description:
fsck_ffs(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
diffstat:
sbin/fsck_ffs/inode.c | 8 +++++---
sbin/fsck_ffs/setup.c | 16 +++++++++++-----
sbin/fsck_ffs/utilities.c | 13 +++++++++----
3 files changed, 25 insertions(+), 12 deletions(-)
diffs (135 lines):
diff -r 26a833bf34bf -r 05b3b074ab1c sbin/fsck_ffs/inode.c
--- a/sbin/fsck_ffs/inode.c Tue Jul 04 19:24:25 2023 +0000
+++ b/sbin/fsck_ffs/inode.c Tue Jul 04 20:40:22 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: inode.c,v 1.75 2023/01/14 17:01:10 kre Exp $ */
+/* $NetBSD: inode.c,v 1.76 2023/07/04 20:40:22 riastradh Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)inode.c 8.8 (Berkeley) 4/28/95";
#else
-__RCSID("$NetBSD: inode.c,v 1.75 2023/01/14 17:01:10 kre Exp $");
+__RCSID("$NetBSD: inode.c,v 1.76 2023/07/04 20:40:22 riastradh Exp $");
#endif
#endif /* not lint */
@@ -462,8 +462,10 @@ setinodebuf(ino_t inum)
partialcnt = fullcnt;
partialsize = inobufsize;
}
+ __CTASSERT(powerof2(DEV_BSIZE));
if (inodebuf == NULL &&
- (inodebuf = aligned_alloc(DEV_BSIZE, (unsigned)inobufsize)) == NULL)
+ (inodebuf = aligned_alloc(DEV_BSIZE,
+ roundup2((unsigned)inobufsize, DEV_BSIZE))) == NULL)
errexit("Cannot allocate space for inode buffer");
}
diff -r 26a833bf34bf -r 05b3b074ab1c sbin/fsck_ffs/setup.c
--- a/sbin/fsck_ffs/setup.c Tue Jul 04 19:24:25 2023 +0000
+++ b/sbin/fsck_ffs/setup.c Tue Jul 04 20:40:22 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: setup.c,v 1.106 2023/01/08 05:25:24 chs Exp $ */
+/* $NetBSD: setup.c,v 1.107 2023/07/04 20:40:22 riastradh Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)setup.c 8.10 (Berkeley) 5/9/95";
#else
-__RCSID("$NetBSD: setup.c,v 1.106 2023/01/08 05:25:24 chs Exp $");
+__RCSID("$NetBSD: setup.c,v 1.107 2023/07/04 20:40:22 riastradh Exp $");
#endif
#endif /* not lint */
@@ -127,6 +127,7 @@ setup(const char *dev, const char *origd
lfdir = 0;
initbarea(&sblk);
initbarea(&asblk);
+ __CTASSERT((SBLOCKSIZE % DEV_BSIZE) == 0);
sblk.b_un.b_buf = aligned_alloc(DEV_BSIZE, SBLOCKSIZE);
sblock = aligned_alloc(DEV_BSIZE, SBLOCKSIZE);
asblk.b_un.b_buf = aligned_alloc(DEV_BSIZE, SBLOCKSIZE);
@@ -459,8 +460,9 @@ setup(const char *dev, const char *origd
* read in the summary info.
*/
asked = 0;
+ __CTASSERT(powerof2(DEV_BSIZE));
sblock->fs_csp = (struct csum *)aligned_alloc(DEV_BSIZE,
- sblock->fs_cssize);
+ roundup2(sblock->fs_cssize, DEV_BSIZE));
if (sblock->fs_csp == NULL) {
pwarn("cannot alloc %u bytes for summary info\n",
sblock->fs_cssize);
@@ -495,7 +497,9 @@ setup(const char *dev, const char *origd
* allocate and initialize the necessary maps
*/
bmapsize = roundup(howmany(maxfsblock, NBBY), sizeof(int16_t));
- blockmap = aligned_alloc(DEV_BSIZE, (unsigned)bmapsize);
+ __CTASSERT(powerof2(DEV_BSIZE));
+ blockmap = aligned_alloc(DEV_BSIZE,
+ roundup2((unsigned)bmapsize, DEV_BSIZE));
if (blockmap == NULL) {
pwarn("cannot alloc %u bytes for blockmap\n",
(unsigned)bmapsize);
@@ -530,7 +534,9 @@ setup(const char *dev, const char *origd
(unsigned)(numdirs * sizeof(struct inoinfo *)));
goto badsblabel;
}
- cgrp = aligned_alloc(DEV_BSIZE, sblock->fs_cgsize);
+ __CTASSERT(powerof2(DEV_BSIZE));
+ cgrp = aligned_alloc(DEV_BSIZE,
+ roundup2(sblock->fs_cgsize, DEV_BSIZE));
if (cgrp == NULL) {
pwarn("cannot alloc %u bytes for cylinder group\n",
sblock->fs_cgsize);
diff -r 26a833bf34bf -r 05b3b074ab1c sbin/fsck_ffs/utilities.c
--- a/sbin/fsck_ffs/utilities.c Tue Jul 04 19:24:25 2023 +0000
+++ b/sbin/fsck_ffs/utilities.c Tue Jul 04 20:40:22 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: utilities.c,v 1.68 2023/01/14 12:12:50 christos Exp $ */
+/* $NetBSD: utilities.c,v 1.69 2023/07/04 20:40:22 riastradh Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)utilities.c 8.6 (Berkeley) 5/19/95";
#else
-__RCSID("$NetBSD: utilities.c,v 1.68 2023/01/14 12:12:50 christos Exp $");
+__RCSID("$NetBSD: utilities.c,v 1.69 2023/07/04 20:40:22 riastradh Exp $");
#endif
#endif /* not lint */
@@ -135,12 +135,15 @@ bufinit(void)
char *bufp;
pbp = pdirbp = (struct bufarea *)0;
- bufp = aligned_alloc(DEV_BSIZE, (unsigned int)sblock->fs_bsize);
+ __CTASSERT(powerof2(DEV_BSIZE));
+ bufp = aligned_alloc(DEV_BSIZE,
+ roundup2((unsigned int)sblock->fs_bsize, DEV_BSIZE));
if (bufp == 0)
errexit("cannot allocate buffer pool");
cgblk.b_un.b_buf = bufp;
initbarea(&cgblk);
#ifndef NO_APPLE_UFS
+ __CTASSERT((APPLEUFS_LABEL_SIZE % DEV_BSIZE) == 0);
bufp = aligned_alloc(DEV_BSIZE, (unsigned int)APPLEUFS_LABEL_SIZE);
if (bufp == 0)
errexit("cannot allocate buffer pool");
@@ -153,7 +156,9 @@ bufinit(void)
bufcnt = MINBUFS;
for (i = 0; i < bufcnt; i++) {
bp = malloc(sizeof(struct bufarea));
- bufp = aligned_alloc(DEV_BSIZE, (unsigned int)sblock->fs_bsize);
+ __CTASSERT(powerof2(DEV_BSIZE));
+ bufp = aligned_alloc(DEV_BSIZE,
+ roundup2((unsigned int)sblock->fs_bsize, DEV_BSIZE));
if (bp == NULL || bufp == NULL) {
if (i >= MINBUFS) {
if (bp)
Home |
Main Index |
Thread Index |
Old Index