diff options
author | Otto Moerbeek <otto@cvs.openbsd.org> | 2020-06-20 07:49:05 +0000 |
---|---|---|
committer | Otto Moerbeek <otto@cvs.openbsd.org> | 2020-06-20 07:49:05 +0000 |
commit | 16ffde63ed5fec65ed15f78111aaedac863c845f (patch) | |
tree | ff137516583268193743b9a4c76689dd2fc8d4a8 /sbin/fsck_ffs | |
parent | f297aafeb6506dc92f9bae5d2c7c7a0a49a5f8ce (diff) |
With filesystem having many cylinder groups and many inodes per cg the
ncg * ipg calcualtion can overflow if signed types are used. Move
to uint32_t for the relevant values. Aligned with FreeBSD changes.
Also make sure newfs refuses to create an fs with more that 2^32-1
inodes. ok millert@
Diffstat (limited to 'sbin/fsck_ffs')
-rw-r--r-- | sbin/fsck_ffs/pass1.c | 4 | ||||
-rw-r--r-- | sbin/fsck_ffs/pass1b.c | 4 | ||||
-rw-r--r-- | sbin/fsck_ffs/pass4.c | 5 | ||||
-rw-r--r-- | sbin/fsck_ffs/pass5.c | 22 | ||||
-rw-r--r-- | sbin/fsck_ffs/setup.c | 9 | ||||
-rw-r--r-- | sbin/fsck_ffs/utilities.c | 4 |
6 files changed, 26 insertions, 22 deletions
diff --git a/sbin/fsck_ffs/pass1.c b/sbin/fsck_ffs/pass1.c index 61d5431ecb8..0bc318788c0 100644 --- a/sbin/fsck_ffs/pass1.c +++ b/sbin/fsck_ffs/pass1.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pass1.c,v 1.45 2017/04/12 15:23:08 millert Exp $ */ +/* $OpenBSD: pass1.c,v 1.46 2020/06/20 07:49:04 otto Exp $ */ /* $NetBSD: pass1.c,v 1.16 1996/09/27 22:45:15 christos Exp $ */ /* @@ -66,7 +66,7 @@ pass1(void) ino_t inumber, inosused, ninosused; size_t inospace; struct inostat *info; - int c; + u_int c; struct inodesc idesc; daddr_t i, cgd; u_int8_t *cp; diff --git a/sbin/fsck_ffs/pass1b.c b/sbin/fsck_ffs/pass1b.c index 1bf4e166f48..56a28e3697d 100644 --- a/sbin/fsck_ffs/pass1b.c +++ b/sbin/fsck_ffs/pass1b.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pass1b.c,v 1.21 2015/01/20 18:22:21 deraadt Exp $ */ +/* $OpenBSD: pass1b.c,v 1.22 2020/06/20 07:49:04 otto Exp $ */ /* $NetBSD: pass1b.c,v 1.10 1996/09/23 16:18:37 christos Exp $ */ /* @@ -55,7 +55,7 @@ pass1b_info(char *buf, size_t buflen) void pass1b(void) { - int c, i; + u_int c, i; union dinode *dp; struct inodesc idesc; ino_t inumber; diff --git a/sbin/fsck_ffs/pass4.c b/sbin/fsck_ffs/pass4.c index 2e454d9490e..482f4ee2c41 100644 --- a/sbin/fsck_ffs/pass4.c +++ b/sbin/fsck_ffs/pass4.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pass4.c,v 1.25 2017/04/13 07:30:21 jsg Exp $ */ +/* $OpenBSD: pass4.c,v 1.26 2020/06/20 07:49:04 otto Exp $ */ /* $NetBSD: pass4.c,v 1.11 1996/09/27 22:45:17 christos Exp $ */ /* @@ -59,7 +59,8 @@ pass4(void) struct zlncnt *zlnp; union dinode *dp; struct inodesc idesc; - int n, c, i; + int n, i; + u_int c; memset(&idesc, 0, sizeof(struct inodesc)); idesc.id_type = ADDR; diff --git a/sbin/fsck_ffs/pass5.c b/sbin/fsck_ffs/pass5.c index cdce86c0b6b..9dca5bdce83 100644 --- a/sbin/fsck_ffs/pass5.c +++ b/sbin/fsck_ffs/pass5.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pass5.c,v 1.48 2015/01/20 18:22:21 deraadt Exp $ */ +/* $OpenBSD: pass5.c,v 1.49 2020/06/20 07:49:04 otto Exp $ */ /* $NetBSD: pass5.c,v 1.16 1996/09/27 22:45:18 christos Exp $ */ /* @@ -48,26 +48,28 @@ #define MINIMUM(a, b) (((a) < (b)) ? (a) : (b)) -static int info_cg; -static int info_maxcg; +static u_int info_cg; +static u_int info_maxcg; static int pass5_info(char *buf, size_t buflen) { - return (snprintf(buf, buflen, "phase 5, cg %d/%d", + return (snprintf(buf, buflen, "phase 5, cg %u/%u", info_cg, info_maxcg) > 0); } void pass5(void) { - int c, blk, frags, basesize, sumsize, mapsize, savednrpos=0; + int blk, frags, basesize, sumsize, mapsize, savednrpos=0; + u_int c; int inomapsize, blkmapsize; struct fs *fs = &sblock; struct cg *cg = &cgrp; daddr_t dbase, dmax; daddr_t d; - long i, j, k, rewritecg = 0; + long i, k, rewritecg = 0; + ino_t j; struct csum *cs; struct csum_total cstotal; struct inodesc idesc[3]; @@ -179,7 +181,7 @@ pass5(void) info_cg = c; getblk(&cgblk, cgtod(fs, c), fs->fs_cgsize); if (!cg_chkmagic(cg)) - pfatal("CG %d: BAD MAGIC NUMBER\n", c); + pfatal("CG %u: BAD MAGIC NUMBER\n", c); dbase = cgbase(fs, c); dmax = dbase + fs->fs_fpg; if (dmax > fs->fs_size) @@ -215,7 +217,7 @@ pass5(void) newcg->cg_irotor = cg->cg_irotor; } else { newcg->cg_ncyl = 0; - if ((unsigned)cg->cg_initediblk > fs->fs_ipg) + if (cg->cg_initediblk > fs->fs_ipg) newcg->cg_initediblk = fs->fs_ipg; else newcg->cg_initediblk = cg->cg_initediblk; @@ -339,8 +341,8 @@ pass5(void) continue; if (cg_inosused(cg)[i] & (1 << k)) continue; - pwarn("ALLOCATED INODE %lld MARKED FREE\n", - ((long long)c * fs->fs_ipg + i * 8) + k); + pwarn("ALLOCATED INODE %llu MARKED FREE\n", + ((ino_t)c * fs->fs_ipg + i * 8) + k); } } for (i = 0; i < blkmapsize; i++) { diff --git a/sbin/fsck_ffs/setup.c b/sbin/fsck_ffs/setup.c index d8a97c63ecf..e9c922d7c37 100644 --- a/sbin/fsck_ffs/setup.c +++ b/sbin/fsck_ffs/setup.c @@ -1,4 +1,4 @@ -/* $OpenBSD: setup.c,v 1.66 2019/06/28 13:32:43 deraadt Exp $ */ +/* $OpenBSD: setup.c,v 1.67 2020/06/20 07:49:04 otto Exp $ */ /* $NetBSD: setup.c,v 1.27 1996/09/27 22:45:19 christos Exp $ */ /* @@ -79,14 +79,15 @@ static const int altsbtry[] = { 32, 64, 128, 144, 160, 192, 256 }; int setup(char *dev, int isfsdb) { - long cg, size, asked, i, j; + long size, asked, i, j; size_t bmapsize; struct disklabel *lp; off_t sizepb; struct stat statb; struct fs proto; int doskipclean; - int32_t maxsymlinklen, nindir, inopb; + int32_t maxsymlinklen, nindir; + uint32_t cg, inopb; u_int64_t maxfilesize; char *realdev; @@ -366,7 +367,7 @@ found: else inopb = sblock.fs_bsize / sizeof(struct ufs1_dinode); if (INOPB(&sblock) != inopb) { - pwarn("INCONSISTENT INOPB=%d\n", INOPB(&sblock)); + pwarn("INCONSISTENT INOPB=%u\n", INOPB(&sblock)); sblock.fs_inopb = inopb; if (preen) printf(" (FIXED)\n"); diff --git a/sbin/fsck_ffs/utilities.c b/sbin/fsck_ffs/utilities.c index 663c4a9dcc2..b2f92e4fd36 100644 --- a/sbin/fsck_ffs/utilities.c +++ b/sbin/fsck_ffs/utilities.c @@ -1,4 +1,4 @@ -/* $OpenBSD: utilities.c,v 1.52 2019/02/06 13:26:13 millert Exp $ */ +/* $OpenBSD: utilities.c,v 1.53 2020/06/20 07:49:04 otto Exp $ */ /* $NetBSD: utilities.c,v 1.18 1996/09/27 22:45:20 christos Exp $ */ /* @@ -581,7 +581,7 @@ dofix(struct inodesc *idesc, char *msg) return (0); default: - errexit("UNKNOWN INODESC FIX MODE %d\n", idesc->id_fix); + errexit("UNKNOWN INODESC FIX MODE %u\n", idesc->id_fix); } /* NOTREACHED */ } |