From 5df24050d30dd140d61bac90b670f5d784c29df7 Mon Sep 17 00:00:00 2001 From: riastradh Date: Tue, 4 Jul 2023 20:40:34 +0000 Subject: 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 --- sbin/newfs/mkfs.c | 6 ++++-- sbin/newfs/newfs.c | 8 +++++--- 2 files changed, 9 insertions(+), 5 deletions(-) (limited to 'sbin') diff --git a/sbin/newfs/mkfs.c b/sbin/newfs/mkfs.c index c5c4858e5e8..47cd0819a24 100644 --- a/sbin/newfs/mkfs.c +++ b/sbin/newfs/mkfs.c @@ -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)); diff --git a/sbin/newfs/newfs.c b/sbin/newfs/newfs.c index 1a5d1cf424e..563b9917754 100644 --- a/sbin/newfs/newfs.c +++ b/sbin/newfs/newfs.c @@ -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, 1989, 1993, 1994\ #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); -- cgit