From 2311cd785ae875965a77d848d3f6ee29258fa0fe Mon Sep 17 00:00:00 2001 From: Daimiao Chen Date: Thu, 22 Jan 2026 11:04:59 -0500 Subject: [PATCH 1/2] Guard null callbacks in lfs_dir_fetchmatch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit lfs_dir_fetch relies on an impossible tag match to avoid calling a NULL callback. Add an explicit cb != NULL check in the match path so future refactors don’t risk a NULL function-pointer call. --- lfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lfs.c b/lfs.c index da4bfca4..fce9d3bf 100644 --- a/lfs.c +++ b/lfs.c @@ -1290,7 +1290,7 @@ static lfs_stag_t lfs_dir_fetchmatch(lfs_t *lfs, } // found a match for our fetcher? - if ((fmask & tag) == (fmask & ftag)) { + if ((fmask & tag) == (fmask & ftag) && (cb != NULL)) { int res = cb(data, tag, &(struct lfs_diskoff){ dir->pair[0], off+sizeof(tag)}); if (res < 0) { From fd5e7f62538d727653a50178dbd578bb33ac0ab6 Mon Sep 17 00:00:00 2001 From: daimiao chen Date: Thu, 5 Mar 2026 16:56:03 -0500 Subject: [PATCH 2/2] Using LFS_ASSERT instead of an runtime check. Remove NULL check from condition and assert callback is valid. --- lfs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lfs.c b/lfs.c index fce9d3bf..ecedcd8f 100644 --- a/lfs.c +++ b/lfs.c @@ -1290,7 +1290,8 @@ static lfs_stag_t lfs_dir_fetchmatch(lfs_t *lfs, } // found a match for our fetcher? - if ((fmask & tag) == (fmask & ftag) && (cb != NULL)) { + if ((fmask & tag) == (fmask & ftag)) { + LFS_ASSERT(cb != NULL); int res = cb(data, tag, &(struct lfs_diskoff){ dir->pair[0], off+sizeof(tag)}); if (res < 0) {