Skip to contentSkip to conversation

xfsprogs: xfs_fsr: Verify bulkstat version information in qsort's cmp()

PATCH Superseded Chandan Babu R 2 participants 2 messages Jan 27, 2021

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfsprogs: xfs_fsr: Verify bulkstat version information in qsort's cmp()

This commit introduces a check to verify that correct bulkstat structures are being processed by qsort's cmp() function.

---
 fsr/xfs_fsr.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
fsr/xfs_fsr.c +7 -2
index b885395e..de7e8190 100644
@@ -582,8 +582,13 @@ fsrall_cleanup(int timeout)
 static int
 cmp(const void *s1, const void *s2)
 {
-	return( ((struct xfs_bulkstat *)s2)->bs_extents -
-	        ((struct xfs_bulkstat *)s1)->bs_extents);
+	const struct xfs_bulkstat	*bs1 = s1;
+	const struct xfs_bulkstat	*bs2 = s2;
+
+	ASSERT(bs1->bs_version == XFS_BULKSTAT_VERSION_V5
+		&& bs2->bs_version == XFS_BULKSTAT_VERSION_V5);
+
+	return (bs2->bs_extents - bs1->bs_extents);
 }
 
 /*
Signature · 1 line
2.29.2
#1 lore raw
Quoted 14 lines · Chandan Babu R

This commit introduces a check to verify that correct bulkstat structures are being processed by qsort's cmp() function.

---
 fsr/xfs_fsr.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
fsr/xfs_fsr.c +0 -0
index b885395e..de7e8190 100644

fsr/xfs_fsr.c fsrall_cleanup(int timeout) · line 589

Quoted 10 lines
fsr/xfs_fsr.c +5 -2
@@ -582,8 +582,13 @@ fsrall_cleanup(int timeout)
 static int
 cmp(const void *s1, const void *s2)
 {
-	return( ((struct xfs_bulkstat *)s2)->bs_extents -
-	        ((struct xfs_bulkstat *)s1)->bs_extents);
+	const struct xfs_bulkstat	*bs1 = s1;
+	const struct xfs_bulkstat	*bs2 = s2;
+
+	ASSERT(bs1->bs_version == XFS_BULKSTAT_VERSION_V5
+		&& bs2->bs_version == XFS_BULKSTAT_VERSION_V5);

Stylistic nit: the '&&' goes on the previous line; and bs_version can also be XFS_BULKSTAT_VERSION_V1.

--D

Quoted 8 lines
fsr/xfs_fsr.c +2 -0
+
+	return (bs2->bs_extents - bs1->bs_extents);
 }
 
 /*
Signature · 1 line
2.29.2