Skip to contentSkip to conversation

xfsprogs: coverity fixes

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

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover xfsprogs: coverity fixes

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

---
v2: initialize automatic struct ifake to 0 at declaration instead of
setting individual member if_levels to 0.
---

#1 lore raw

PATCH v2 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 v2 1/4
#2 lore raw

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

Quoted 6 lines · Bill O'Donnell

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

Coverity-id: 1596603

Looks ok,

(didn't hch rvb this earlier?)

--D

Quoted 21 lines
---
 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
#3 lore raw

PATCH v2 2/4 xfs_db: fix unitialized automatic struct ifake to 0.

In reply to Bill O'Donnell

Ensure automatic struct ifake is properly initialized.

Coverity-id: 1596600, 1596597

---
 db/bmap_inflate.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
db/bmap_inflate.c +2 -2
index 33b0c954..219f9bbf 100644
@@ -340,7 +340,7 @@ build_new_datafork(
 	const struct xfs_bmbt_irec	*irec,
 	xfs_extnum_t			nextents)
 {
-	struct xbtree_ifakeroot		ifake;
+	struct xbtree_ifakeroot		ifake = {};
 	struct xfs_btree_cur		*bmap_cur;
 	int				error;
 
@@ -394,7 +394,7 @@ estimate_size(
 		.leaf_slack		= 1,
 		.node_slack		= 1,
 	};
-	struct xbtree_ifakeroot		ifake;
+	struct xbtree_ifakeroot		ifake = {};
 	struct xfs_btree_cur		*bmap_cur;
 	int				error;
 
Signature · 1 line
2.45.2
Reviewed-by on v2 2/4
#4 lore raw

Re: [PATCH v2 2/4] xfs_db: fix unitialized automatic struct ifake to 0.

Quoted 5 lines · Bill O'Donnell

Ensure automatic struct ifake is properly initialized.

Coverity-id: 1596600, 1596597

Looks good now,

--D

Quoted 30 lines
---
 db/bmap_inflate.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
db/bmap_inflate.c +2 -2
index 33b0c954..219f9bbf 100644
@@ -340,7 +340,7 @@ build_new_datafork(
 	const struct xfs_bmbt_irec	*irec,
 	xfs_extnum_t			nextents)
 {
-	struct xbtree_ifakeroot		ifake;
+	struct xbtree_ifakeroot		ifake = {};
 	struct xfs_btree_cur		*bmap_cur;
 	int				error;
 
@@ -394,7 +394,7 @@ estimate_size(
 		.leaf_slack		= 1,
 		.node_slack		= 1,
 	};
-	struct xbtree_ifakeroot		ifake;
+	struct xbtree_ifakeroot		ifake = {};
 	struct xfs_btree_cur		*bmap_cur;
 	int				error;
 
Signature · 1 line
2.45.2
#5 lore raw

PATCH v2 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
#6 lore raw

Re: [PATCH v2 3/4] xfs_fsr: correct type in fsrprintf() call

Quoted 14 lines · 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 +0 -0
index fdd37756..d204e3a4 100644

fsr/xfs_fsr.c fsrallfs(char *mtab, time_t howlong, char *leftofffile) · line 429

Quoted 5 lines
fsr/xfs_fsr.c +1 -1
@@ -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);

The exact definition of time_t varies by platform and architecture. I'd paste that is, but in libc it's a twisty mess of indirection that eventually ends at 'signed long int' or 'long long int'.

Either way, some linter is likely to balk at this, so you might as well cast howlong to (long long) and use %lld here.

--D

Quoted 7 lines
fsr/xfs_fsr.c +0 -0
 	endtime = starttime + howlong;
 	fs = fsbase;
Signature · 1 line
2.45.2
#7 lore raw

Re: [PATCH v2 3/4] xfs_fsr: correct type in fsrprintf() call

Quoted 25 lines · Darrick J. Wong
Quoted 14 lines · 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 +0 -0
index fdd37756..d204e3a4 100644

fsr/xfs_fsr.c fsrallfs(char *mtab, time_t howlong, char *leftofffile) · line 429

Quoted 5 lines
fsr/xfs_fsr.c +1 -1
@@ -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);

The exact definition of time_t varies by platform and architecture. I'd paste that is, but in libc it's a twisty mess of indirection that eventually ends at 'signed long int' or 'long long int'.

Quoted 2 lines

Either way, some linter is likely to balk at this, so you might as well cast howlong to (long long) and use %lld here.

Good idea. I'll send a v3.
Thanks-
Bill

Quoted 11 lines

--D

Quoted 7 lines
fsr/xfs_fsr.c +0 -0
 	endtime = starttime + howlong;
 	fs = fsbase;
Signature · 1 line
2.45.2
#8 lore raw

PATCH v2 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
Reviewed-by on v2 4/4
#9 lore raw

Re: [PATCH v2 4/4] xfs_repair: correct type of variable global_msgs.interval to time_t

Quoted 5 lines · Bill O'Donnell

Use time_t instead of int for interval field.

Coverity-id: 1596599

Hopefully the intervals never get that big, but yes, we could use a time interval type instead of the ever popular int.

--D

Quoted 21 lines
---
 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