Skip to contentSkip to conversation

erofs-utils: lib: fix `ictx` leak in the failure path

PATCH New Gao Xiang 1 participant 7 messages Jun 30 Library code

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH 1/7 erofs-utils: lib: fix `ictx` leak in the failure path

Coverity-id: 647272

---
 lib/compress.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
lib/compress.c +5 -3
index e57de425be28..f7ad5a1c6c87 100644
@@ -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
author
#1 lore raw

PATCH 2/7 erofs-utils: lib: silence `INTEGER_OVERFLOW`

Coverity-id: 647269

---
 lib/metabox.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
lib/metabox.c +5 -1
index 86a708367dc0..5c2eadacaf7f 100644
@@ -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
author
#2 lore raw

PATCH 3/7 erofs-utils: lib: fix `PRINTF_ARGS`

In reply to Gao Xiang

Coverity-id: 647268

---
 lib/blobchunk.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
lib/blobchunk.c +3 -2
index d3f922d37739..0523873570a2 100644
@@ -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
author
#3 lore raw

PATCH 4/7 erofs-utils: mount: fix `RESOURCE_LEAK`

In reply to Gao Xiang

Coverity-id: 647264

---
 mount/main.c | 1 +
 1 file changed, 1 insertion(+)
mount/main.c +1 -0
index 48418275b2d0..ffe718a0a90f 100644
@@ -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
author
#4 lore raw

PATCH 5/7 erofs-utils: lib: fix `STRING_NULL` in nbd.c

In reply to Gao Xiang

Coverity-id: 647257

---
 lib/backends/nbd.c | 1 +
 1 file changed, 1 insertion(+)
lib/backends/nbd.c +1 -0
index c488053d99d3..db0df44990b6 100644
@@ -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
author
#5 lore raw

PATCH 6/7 erofs-utils: mount: fix `RESOURCE_LEAK`

In reply to Gao Xiang

Coverity-id: 647246

---
 mount/main.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
mount/main.c +5 -2
index ffe718a0a90f..ec27dcb53eb3 100644
@@ -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
author
#6 lore raw

PATCH 7/7 erofs-utils: lib: silence `INTEGER_OVERFLOW`

In reply to Gao Xiang

Coverity-id: 647247

---
 lib/inode.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
lib/inode.c +4 -1
index 9f1553e8db2b..267694f83fdf 100644
@@ -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