File xfs_copy-bail-out-early-when-superblock-cannot-be-ve.patch of Package xfsprogs.35236

From 10ac1f62f1faf794805d1072593c69540c0e2739 Mon Sep 17 00:00:00 2001
From: Anthony Iliopoulos <ailiop@suse.com>
Date: Sat, 29 Jun 2024 16:41:34 +0200
Subject: [PATCH] xfs_copy: bail out early when superblock cannot be verified
Patch-mainline: no (baf8a5df8a0c)
References: bsc#1227150

xfs_copy will crash when an invalid input will be presented to it (e.g.
a non-xfs filesystem), due to a division by zero. Fix that by exiting
when the superblock cannot be properly verified.

This also fixes xfs/082.

Upstream handles this via xfsprogs commit baf8a5df8a0c which was
introduced in v5.19.0, as a fix for commit f8b581d6769d, which was
merged upstream in v5.9.0.

Since we do not carry any of the above two commits in SLE12-SP5
xfsprogs, we fix this issue locally with a simpler patch to avoid
backporting the whole lot of changes and dependent commits that were
introduced by f8b581d6769d.

Signed-off-by: Anthony Iliopoulos <ailiop@suse.com>
---
 copy/xfs_copy.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/copy/xfs_copy.c b/copy/xfs_copy.c
index 16ee4d9c5180..98474a693bc5 100644
--- a/copy/xfs_copy.c
+++ b/copy/xfs_copy.c
@@ -736,6 +736,13 @@ main(int argc, char **argv)
 	sbp = libxfs_readbuf(mbuf.m_ddev_targp, XFS_SB_DADDR,
 			     1 << (sb->sb_sectlog - BBSHIFT),
 			     0, &xfs_sb_buf_ops);
+
+	if (!sbp || sbp->b_error) {
+		do_log(_("%s: couldn't read superblock, error=%d\n"),
+			progname, -sbp->b_error);
+		exit(1);
+	}
+
 	libxfs_putbuf(sbp);
 
 	mp = libxfs_mount(&mbuf, sb, xargs.ddev, xargs.logdev, xargs.rtdev, 0);
-- 
2.44.0

openSUSE Build Service is sponsored by