All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chandan Babu R <chandanrlinux@gmail.com>
To: linux-xfs@vger.kernel.org
Cc: Chandan Babu R <chandanrlinux@gmail.com>,
	sandeen@sandeen.net, "Darrick J . Wong" <djwong@kernel.org>
Subject: [PATCH] xfsprogs: xfs_fsr: Verify bulkstat version information in qsort's cmp()
Date: Wed, 27 Jan 2021 14:54:05 +0530	[thread overview]
Message-ID: <20210127092405.2841857-1-chandanrlinux@gmail.com> (raw)

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

Suggested-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandanrlinux@gmail.com>
---
 fsr/xfs_fsr.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/fsr/xfs_fsr.c b/fsr/xfs_fsr.c
index b885395e..de7e8190 100644
--- a/fsr/xfs_fsr.c
+++ b/fsr/xfs_fsr.c
@@ -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);
 }
 
 /*
-- 
2.29.2


             reply	other threads:[~2021-01-27  9:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-27  9:24 Chandan Babu R [this message]
2021-01-27 16:34 ` [PATCH] xfsprogs: xfs_fsr: Verify bulkstat version information in qsort's cmp() Darrick J. Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210127092405.2841857-1-chandanrlinux@gmail.com \
    --to=chandanrlinux@gmail.com \
    --cc=djwong@kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=sandeen@sandeen.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.