Skip to contentSkip to conversation

xfsprogs: coverity fixes

PATCH Superseded Bill O'Donnell 2 participants 10 messages Jun 13, 2024

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover xfsprogs: coverity fixes

Select fixes made following coverity scan results on 05/23/2024.
CID: 1596597, 1596598, 1596599, 1596600, 1596603

Signed-off-by <[email protected]>
#1 lore raw

PATCH 1/4 mkfs.xfs: avoid potential overflowing expression in xfs_mkfs.c

Cast max_tx_bytes to uint64_t to avoid overflowing expression in calc_concurrency_logblocks().

Coverity-id: 1596603

---
 mkfs/xfs_mkfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mkfs/xfs_mkfs.c +1 -1
index f4a9bf20..2f801dd4 100644
@@ -3678,7 +3678,7 @@ calc_concurrency_logblocks(
 	 * without blocking for space.  Increase the figure by 50% so that
 	 * background threads can also run.
 	 */
-	log_bytes = max_tx_bytes * 3 * cli->log_concurrency / 2;
+	log_bytes = (uint64_t)max_tx_bytes * 3 * cli->log_concurrency / 2;
 	new_logblocks = min(XFS_MAX_LOG_BYTES >> cfg->blocklog,
 				log_bytes >> cfg->blocklog);
 
Signature · 1 line
2.45.2
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] mkfs.xfs: avoid potential overflowing expression in xfs_mkfs.c

Looks good:

Quoted 8 lines
mkfs/xfs_mkfs.c +1 -0
+	log_bytes = (uint64_t)max_tx_bytes * 3 * cli->log_concurrency / 2;
 	new_logblocks = min(XFS_MAX_LOG_BYTES >> cfg->blocklog,
 				log_bytes >> cfg->blocklog);
Signature · 2 lines
-- 
2.45.2

---end quoted text---

#3 lore raw

PATCH 2/4 xfs_db: fix unitialized variable ifake->if_levels

In reply to Bill O'Donnell

Initialize if_levels to 0.

Coverity-id: 1596600, 1596597

---
 db/bmap_inflate.c | 2 ++
 1 file changed, 2 insertions(+)
db/bmap_inflate.c +2 -0
index 33b0c954..8232f486 100644
@@ -351,6 +351,7 @@ build_new_datafork(
 	/* Set up staging for the new bmbt */
 	ifake.if_fork = kmem_cache_zalloc(xfs_ifork_cache, 0);
 	ifake.if_fork_size = xfs_inode_fork_size(ip, XFS_DATA_FORK);
+	ifake.if_levels = 0;
 	bmap_cur = libxfs_bmbt_stage_cursor(ip->i_mount, ip, &ifake);
 
 	/*
@@ -404,6 +405,7 @@ estimate_size(
 
 	ifake.if_fork = kmem_cache_zalloc(xfs_ifork_cache, 0);
 	ifake.if_fork_size = xfs_inode_fork_size(ip, XFS_DATA_FORK);
+	ifake.if_levels = 0;
 
 	bmap_cur = libxfs_bmbt_stage_cursor(ip->i_mount, ip, &ifake);
 	error = -libxfs_btree_bload_compute_geometry(bmap_cur, &bmap_bload,
Signature · 1 line
2.45.2
#4 lore raw

Re: [PATCH 2/4] xfs_db: fix unitialized variable ifake->if_levels

Quoted 22 lines · Bill O'Donnell

Initialize if_levels to 0.

Coverity-id: 1596600, 1596597

---
 db/bmap_inflate.c | 2 ++
 1 file changed, 2 insertions(+)
db/bmap_inflate.c +1 -0
index 33b0c954..8232f486 100644
@@ -351,6 +351,7 @@ build_new_datafork(
 	/* Set up staging for the new bmbt */
 	ifake.if_fork = kmem_cache_zalloc(xfs_ifork_cache, 0);
 	ifake.if_fork_size = xfs_inode_fork_size(ip, XFS_DATA_FORK);
+	ifake.if_levels = 0;
 	bmap_cur = libxfs_bmbt_stage_cursor(ip->i_mount, ip, &ifake);
 
 	/*

db/bmap_inflate.c estimate_size( · line 408

Quoted 4 lines
db/bmap_inflate.c +1 -0
@@ -404,6 +405,7 @@ estimate_size(
 
 	ifake.if_fork = kmem_cache_zalloc(xfs_ifork_cache, 0);
 	ifake.if_fork_size = xfs_inode_fork_size(ip, XFS_DATA_FORK);
+	ifake.if_levels = 0;

Maybe initialize it at declaration time by doing:

	struct xbtree_ifakeroot		ifake = { };

to future-proof against adding more fields?

#5 lore raw

Re: [PATCH 2/4] xfs_db: fix unitialized variable ifake->if_levels

Quoted 30 lines · Christoph Hellwig
Quoted 22 lines · Bill O'Donnell

Initialize if_levels to 0.

Coverity-id: 1596600, 1596597

---
 db/bmap_inflate.c | 2 ++
 1 file changed, 2 insertions(+)
db/bmap_inflate.c +1 -0
index 33b0c954..8232f486 100644
@@ -351,6 +351,7 @@ build_new_datafork(
 	/* Set up staging for the new bmbt */
 	ifake.if_fork = kmem_cache_zalloc(xfs_ifork_cache, 0);
 	ifake.if_fork_size = xfs_inode_fork_size(ip, XFS_DATA_FORK);
+	ifake.if_levels = 0;
 	bmap_cur = libxfs_bmbt_stage_cursor(ip->i_mount, ip, &ifake);
 
 	/*

db/bmap_inflate.c estimate_size( · line 408

Quoted 4 lines
db/bmap_inflate.c +1 -0
@@ -404,6 +405,7 @@ estimate_size(
 
 	ifake.if_fork = kmem_cache_zalloc(xfs_ifork_cache, 0);
 	ifake.if_fork_size = xfs_inode_fork_size(ip, XFS_DATA_FORK);
+	ifake.if_levels = 0;

Maybe initialize it at declaration time by doing:

Quoted 4 lines
	struct xbtree_ifakeroot		ifake = { };

to future-proof against adding more fields?

Makes sense, I'll send a new version.
Thanks-
Bill

#6 lore raw

PATCH 3/4 xfs_fsr: correct type in fsrprintf() call

In reply to Bill O'Donnell

Use %ld instead of %d for howlong variable.

Coverity-id: 1596598

---
 fsr/xfs_fsr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fsr/xfs_fsr.c +1 -1
index fdd37756..d204e3a4 100644
@@ -426,7 +426,7 @@ fsrallfs(char *mtab, time_t howlong, char *leftofffile)
 	fsdesc_t *fsp;
 	struct stat sb, sb2;
 
-	fsrprintf("xfs_fsr -m %s -t %d -f %s ...\n", mtab, howlong, leftofffile);
+	fsrprintf("xfs_fsr -m %s -t %ld -f %s ...\n", mtab, howlong, leftofffile);
 
 	endtime = starttime + howlong;
 	fs = fsbase;
Signature · 1 line
2.45.2
#8 lore raw

PATCH 4/4 xfs_repair: correct type of variable global_msgs.interval to time_t

In reply to Bill O'Donnell

Use time_t instead of int for interval field.

Coverity-id: 1596599

---
 repair/progress.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
repair/progress.c +1 -1
index 2ce36cef..15455a99 100644
@@ -91,7 +91,7 @@ typedef struct msg_block_s {
 	uint64_t	*done;
 	uint64_t	*total;
 	int		count;
-	int		interval;
+	time_t		interval;
 } msg_block_t;
 static msg_block_t 	global_msgs;
 
Signature · 1 line
2.45.2