Skip to contentSkip to conversation

squashfs: Fix ambiguity in get_comp_opts() return value handling

PATCH New Ingyu Jang 1 participant 1 message Jan 16, 2025 SquashFS file system

lore
Share & tools
lore

Ingyu Jang

author
#0 lore raw

PATCH 1/1 squashfs: Fix ambiguity in get_comp_opts() return value handling

The return value of the function get_comp_opts() is
checked using IS_ERR().
However, it can return NULL when squashfs_comp_opts() returns NULL, causing ambiguity in its return value.
This makes it difficult for the caller to clearly determine whether the function succeeded or an error occurred.
Additionally, it may cause a NULL pointer dereference.

To address this issue, get_comp_opts() has been modified to always return an appropriate error code wrapped with ERR_PTR() in case of failure.
With this change, the caller can reliably distinguish between success and error cases using IS_ERR().

---
 fs/squashfs/decompressor.c | 2 ++
 1 file changed, 2 insertions(+)
fs/squashfs/decompressor.c +2 -0
index a676084be27e..2988f2d4220c 100644
@@ -117,6 +117,8 @@ static void *get_comp_opts(struct super_block *sb, unsigned short flags)
 	}
 
 	comp_opts = squashfs_comp_opts(msblk, buffer, length);
+	if (!comp_opts)
+		comp_opts = ERR_PTR(-EINVAL);
 
 out:
 	kfree(actor);
Signature · 1 line
2.34.1