git: 06077dc327ea - main - makefs: Fix undefined behaviour in ffs.c
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 16 Jul 2025 15:08:39 UTC
The branch main has been updated by bnovkov:
URL: https://cgit.FreeBSD.org/src/commit/?id=06077dc327eae05026dde958c7a275b8b5bae3b9
commit 06077dc327eae05026dde958c7a275b8b5bae3b9
Author: Bojan Novković <bnovkov@FreeBSD.org>
AuthorDate: 2025-06-25 09:45:06 +0000
Commit: Bojan Novković <bnovkov@FreeBSD.org>
CommitDate: 2025-07-16 15:06:11 +0000
makefs: Fix undefined behaviour in ffs.c
Fix a UBSAN-reported error in `ffs_make_dirbuf` where a zero offset
gets applied to a NULL pointer.
Sponsored by: Klara, Inc.
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D51037
Reviewed by: emaste, mckusick
---
usr.sbin/makefs/ffs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/usr.sbin/makefs/ffs.c b/usr.sbin/makefs/ffs.c
index 4efcd20ad91a..c0fcadf11fba 100644
--- a/usr.sbin/makefs/ffs.c
+++ b/usr.sbin/makefs/ffs.c
@@ -1056,7 +1056,7 @@ ffs_make_dirbuf(dirbuf_t *dbuf, const char *name, fsnode *node, int needswap)
reclen = DIRSIZ_SWAP(0, &de, needswap);
de.d_reclen = ufs_rw16(reclen, needswap);
- dp = (struct direct *)(dbuf->buf + dbuf->cur);
+ dp = dbuf->buf == NULL ? NULL : (struct direct *)(dbuf->buf + dbuf->cur);
llen = 0;
if (dp != NULL)
llen = DIRSIZ_SWAP(0, dp, needswap);