[PATCH] Squashfs: Add check for cache->entry to avoid NULL pointer dereference
From: Jiasheng Jiang
Date: Fri Jan 31 2025 - 15:26:31 EST
Add a check for "cache->entry". Otherwise, if the allocation for
"cache->entry" fails, "cache->entry[i].data" will cause a NULL pointer
dereference.
Fixes: f400e12656ab ("Squashfs: cache operations")
Signed-off-by: Jiasheng Jiang <jiashengjiangcool@xxxxxxxxx>
---
fs/squashfs/cache.c | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/fs/squashfs/cache.c b/fs/squashfs/cache.c
index 4db0d2b0aab8..5a3081583ea9 100644
--- a/fs/squashfs/cache.c
+++ b/fs/squashfs/cache.c
@@ -201,16 +201,19 @@ void squashfs_cache_delete(struct squashfs_cache *cache)
if (cache == NULL)
return;
- for (i = 0; i < cache->entries; i++) {
- if (cache->entry[i].data) {
- for (j = 0; j < cache->pages; j++)
- kfree(cache->entry[i].data[j]);
- kfree(cache->entry[i].data);
+ if (cache->entry) {
+ for (i = 0; i < cache->entries; i++) {
+ if (cache->entry[i].data) {
+ for (j = 0; j < cache->pages; j++)
+ kfree(cache->entry[i].data[j]);
+ kfree(cache->entry[i].data);
+ }
+ kfree(cache->entry[i].actor);
}
- kfree(cache->entry[i].actor);
+
+ kfree(cache->entry);
}
- kfree(cache->entry);
kfree(cache);
}
--
2.25.1