erofs-utils: lib: fix `ictx` leak in the failure path
PATCH 1/7 erofs-utils: lib: fix `ictx` leak in the failure path
Coverity-id: 647272
Signed-off-by Gao Xiang <[email protected]>
--- lib/compress.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
lib/compress.c +5 -3
@@ -1881,8 +1881,7 @@ void *erofs_prepare_compressed_file(struct erofs_importer *im,if (!erofs_sb_has_48bit (sbi)) {erofs_err ("Unaligned compressed extents must be used with the 48bit encoded extent layout" , ictx->max_compressed_extent_size); -free (ictx); -return ERR_PTR (-EINVAL ); + goto err_out; } ictx->data_unaligned = true; }else {
@@ -1894,7 +1893,7 @@ void *erofs_prepare_compressed_file(struct erofs_importer *im,if (ictx->max_compressed_extent_size <erofs_blksiz (sbi)) {erofs_err ("Maximum compressed extent size (%u) must be at least the block size (%u)" , ictx->max_compressed_extent_size,erofs_blksiz (sbi)); -return ERR_PTR (-EINVAL ); + goto err_out; } }else { ictx->max_compressed_extent_size =
@@ -1910,6 +1909,9 @@ void *erofs_prepare_compressed_file(struct erofs_importer *im, ictx->fragemitted = false; ictx->dedupe = false;return ictx; +err_out: +free (ictx); +return ERR_PTR (-EINVAL ); } void erofs_bind_compressed_file_with_fd(struct z_erofs_compress_ictx *ictx,
Signature · 1 line
2.43.5
PATCH 2/7 erofs-utils: lib: silence `INTEGER_OVERFLOW`
Coverity-id: 647269
Signed-off-by Gao Xiang <[email protected]>
--- lib/metabox.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
lib/metabox.c +5 -1
@@ -133,6 +133,10 @@ int erofs_metazone_flush(struct erofs_sb_info *sbi)return PTR_ERR (bh);erofs_mapbh (NULL , bh->block); pos_out =erofs_btell (bh, false); +if (__erofs_unlikely (pos_out ==EROFS_NULL_ADDR )) { +erofs_bdrop (bh, true); +return -EFAULT ; + } meta_blkaddr = pos_out >> sbi->blkszbits; sbi->metazone_startblk = meta_blkaddr;
@@ -148,7 +152,7 @@ int erofs_metazone_flush(struct erofs_sb_info *sbi) do { count = min_t(erofs_off_t, length, INT_MAX); - ret = erofs_io_xcopy(sbi->bmgr->vf, pos_out, + ret = erofs_io_xcopy(sbi->bmgr->vf, (off_t)pos_out, &m2gr->vf, count, false); if (ret < 0) break;
Signature · 1 line
2.43.5
PATCH 3/7 erofs-utils: lib: fix `PRINTF_ARGS`
In reply to Gao XiangCoverity-id: 647268
Signed-off-by Gao Xiang <[email protected]>
--- lib/blobchunk.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
lib/blobchunk.c +3 -2
@@ -361,8 +361,9 @@ int erofs_blob_write_chunked_file(struct erofs_inode *inode, int fd, erofs_strerror(ret)); goto err; } -erofs_dbg ("Align /%s on block #%d (0x%llx)" , -erofs_fspath (inode->i_srcpath),erofs_blknr (sbi, off), off); +erofs_dbg ("Align /%s on block #%llu (0x%llx)" , +erofs_fspath (inode->i_srcpath), +erofs_blknr (sbi, off) |0ULL , off); }for (pos =0 ; pos < inode->i_size; pos += len) {
Signature · 1 line
2.43.5
PATCH 4/7 erofs-utils: mount: fix `RESOURCE_LEAK`
In reply to Gao XiangCoverity-id: 647264
Signed-off-by Gao Xiang <[email protected]>
--- mount/main.c | 1 + 1 file changed, 1 insertion(+)
mount/main.c +1 -0
@@ -552,6 +552,7 @@ static int erofsmount_fuse(const char *source, const char *mountpoint,/* execvp() doesn't work for external mount helpers here */ err =execl ("/bin/sh" ,"/bin/sh" ,"-c" , command,NULL ); +free (command);if (err <0 ) {perror ("failed to execute /bin/sh" );return -errno;
Signature · 1 line
2.43.5
PATCH 5/7 erofs-utils: lib: fix `STRING_NULL` in nbd.c
In reply to Gao XiangCoverity-id: 647257
Signed-off-by Gao Xiang <[email protected]>
--- lib/backends/nbd.c | 1 + 1 file changed, 1 insertion(+)
lib/backends/nbd.c +1 -0
@@ -82,6 +82,7 @@ long erofs_nbd_in_service(int nbdnum)return err; }close (fd); + s[sizeof (s) -1 ] ='\0' ;return strtol (s,NULL ,10 ); }
Signature · 1 line
2.43.5
PATCH 6/7 erofs-utils: mount: fix `RESOURCE_LEAK`
In reply to Gao XiangCoverity-id: 647246
Signed-off-by Gao Xiang <[email protected]>
--- mount/main.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
mount/main.c +5 -2
@@ -1698,8 +1698,11 @@ static int erofsmount_loopmount(const char *source, const char *mountpoint,return -errno; num =ioctl (fd,LOOP_CTL_GET_FREE ); -if (num <0 ) -return -errno; +if (num <0 ) { + dfd = -errno; +close (fd); +return dfd; + }close (fd);snprintf (device,sizeof (device),"/dev/loop%d" , num);
Signature · 1 line
2.43.5
PATCH 7/7 erofs-utils: lib: silence `INTEGER_OVERFLOW`
In reply to Gao XiangCoverity-id: 647247
Signed-off-by Gao Xiang <[email protected]>
--- lib/inode.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
lib/inode.c +4 -1
@@ -670,10 +670,13 @@ static int erofs_write_unencoded_data(struct erofs_inode *inode,if (bh) { bmgr = (struct erofs_bufmgr *)bh->block->buffers.fsprivate; pos =erofs_btell (bh, false); +if (__erofs_unlikely (pos ==EROFS_NULL_ADDR )) +return -EFAULT ; + do { len = min_t(u64, remaining, round_down(UINT_MAX, 1U << sbi->blkszbits)); - ret = erofs_io_xcopy(bmgr->vf, pos, vf, len, noseek); + ret = erofs_io_xcopy(bmgr->vf, (off_t)pos, vf, len, noseek); if (ret) return ret; pos += len;
Signature · 1 line
2.43.5