erofs-utils: lib: fix wrong NULL check after erofs_balloc() in metabox
PATCH 1/1 erofs-utils: lib: fix wrong NULL check after erofs_balloc() in metabox
erofs_balloc() returns an error pointer via ERR_PTR(-errno) on failure, never NULL. The previous check:
if (!bh)
fails to detect error pointers since ERR_PTR encodes errors as non-zero pointers near ULONG_MAX. This causes PTR_ERR(bh) on the next line to be unreachable, and the subsequent erofs_mapbh() call to receive an invalid pointer, potentially causing a crash or silent memory corruption.
Replace with the correct IS_ERR() pattern which properly detects all error pointer values returned by erofs_balloc().
Fixes 7928074b7643 ("erofs-utils: introduce metadata compression [metabox]")
Signed-off-by Utkal Singh <[email protected]>
--- lib/metabox.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/metabox.c +1 -1
@@ -127,7 +127,7 @@ int erofs_metazone_flush(struct erofs_sb_info *sbi)if (!m2gr)return 0 ; bh =erofs_balloc (sbi->bmgr,DATA ,0 ,0 ); -if (!bh) +if (IS_ERR (bh))return PTR_ERR (bh);erofs_mapbh (NULL , bh->block); pos_out =erofs_btell (bh, false);
Signature · 1 line
2.43.0