Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 15 Jun 2021 00:23:35 GMT
From:      Jessica Clarke <jrtc27@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 7ef082733bf8 - main - makefs: Cast daddr_t to off_t before multiplication
Message-ID:  <202106150023.15F0NZYa095247@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by jrtc27:

URL: https://cgit.FreeBSD.org/src/commit/?id=7ef082733bf8989797b71025ba6d597a7d17d92b

commit 7ef082733bf8989797b71025ba6d597a7d17d92b
Author:     Nathaniel Filardo <nwf20@cl.cam.ac.uk>
AuthorDate: 2021-06-15 00:18:36 +0000
Commit:     Jessica Clarke <jrtc27@FreeBSD.org>
CommitDate: 2021-06-15 00:22:04 +0000

    makefs: Cast daddr_t to off_t before multiplication
    
    Apparently some large-file systems out there, such as my powerpc64le
    Linux box, define daddr_t as a 32-bit type, which is sad and stymies
    cross-building disk images.  Cast daddr_t to off_t before doing
    arithmetic that overflows.
    
    Reviewed by:    arichardson, jrtc27, imp
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D27458
---
 usr.sbin/makefs/ffs/buf.c  | 4 ++--
 usr.sbin/makefs/ffs/mkfs.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/usr.sbin/makefs/ffs/buf.c b/usr.sbin/makefs/ffs/buf.c
index ccbfd8ae1e23..13f3099c4491 100644
--- a/usr.sbin/makefs/ffs/buf.c
+++ b/usr.sbin/makefs/ffs/buf.c
@@ -70,7 +70,7 @@ bread(struct m_vnode *vp, daddr_t blkno, int size, struct ucred *u1 __unused,
 		printf("%s: blkno %lld size %d\n", __func__, (long long)blkno,
 		    size);
 	*bpp = getblk(vp, blkno, size, 0, 0, 0);
-	offset = (*bpp)->b_blkno * fs->sectorsize + fs->offset;
+	offset = (off_t)(*bpp)->b_blkno * fs->sectorsize + fs->offset;
 	if (debug & DEBUG_BUF_BREAD)
 		printf("%s: blkno %lld offset %lld bcount %ld\n", __func__,
 		    (long long)(*bpp)->b_blkno, (long long) offset,
@@ -130,7 +130,7 @@ bwrite(struct m_buf *bp)
 	fsinfo_t *fs = bp->b_fs;
 
 	assert (bp != NULL);
-	offset = bp->b_blkno * fs->sectorsize + fs->offset;
+	offset = (off_t)bp->b_blkno * fs->sectorsize + fs->offset;
 	if (debug & DEBUG_BUF_BWRITE)
 		printf("bwrite: blkno %lld offset %lld bcount %ld\n",
 		    (long long)bp->b_blkno, (long long) offset,
diff --git a/usr.sbin/makefs/ffs/mkfs.c b/usr.sbin/makefs/ffs/mkfs.c
index a22a604fe501..0f8b040d6997 100644
--- a/usr.sbin/makefs/ffs/mkfs.c
+++ b/usr.sbin/makefs/ffs/mkfs.c
@@ -794,7 +794,7 @@ ffs_rdfs(daddr_t bno, int size, void *bf, const fsinfo_t *fsopts)
 	int n;
 	off_t offset;
 
-	offset = bno * fsopts->sectorsize + fsopts->offset;
+	offset = (off_t)bno * fsopts->sectorsize + fsopts->offset;
 	if (lseek(fsopts->fd, offset, SEEK_SET) < 0)
 		err(1, "%s: seek error for sector %lld", __func__,
 		    (long long)bno);
@@ -818,7 +818,7 @@ ffs_wtfs(daddr_t bno, int size, void *bf, const fsinfo_t *fsopts)
 	int n;
 	off_t offset;
 
-	offset = bno * fsopts->sectorsize + fsopts->offset;
+	offset = (off_t)bno * fsopts->sectorsize + fsopts->offset;
 	if (lseek(fsopts->fd, offset, SEEK_SET) < 0)
 		err(1, "%s: seek error for sector %lld", __func__,
 		    (long long)bno);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202106150023.15F0NZYa095247>