Blame SOURCES/0019-libblkid-check-fsync-return-code.patch

dbeef3
From f02e9004303df5ab3d9b868f6f60af44663cce69 Mon Sep 17 00:00:00 2001
dbeef3
From: Karel Zak <kzak@redhat.com>
dbeef3
Date: Tue, 19 Apr 2022 09:44:07 +0200
dbeef3
Subject: libblkid: check fsync() return code
dbeef3
dbeef3
Since 39f5af25982d8b0244000e92a9d0e0e6557d0e17 libblkid uses
dbeef3
O_NONBLOCK. Now it's more obvious that check fsync() (and close())
dbeef3
return value after write() is always a good idea ...
dbeef3
dbeef3
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2074486
dbeef3
Upstream: http://github.com/util-linux/util-linux/commit/133a0d70f637b4f4e4337811e452153b04f2bdcf
dbeef3
Signed-off-by: Karel Zak <kzak@redhat.com>
dbeef3
---
dbeef3
 libblkid/src/probe.c | 5 ++++-
dbeef3
 misc-utils/wipefs.c  | 8 ++++++--
dbeef3
 2 files changed, 10 insertions(+), 3 deletions(-)
dbeef3
dbeef3
diff --git a/libblkid/src/probe.c b/libblkid/src/probe.c
dbeef3
index 5f01bc3b3..d317dc19a 100644
dbeef3
--- a/libblkid/src/probe.c
dbeef3
+++ b/libblkid/src/probe.c
dbeef3
@@ -1298,7 +1298,10 @@ int blkid_do_wipe(blkid_probe pr, int dryrun)
dbeef3
 		/* wipen on device */
dbeef3
 		if (write_all(fd, buf, len))
dbeef3
 			return -1;
dbeef3
-		fsync(fd);
dbeef3
+
dbeef3
+		if (fsync(fd) != 0)
dbeef3
+			return -1;
dbeef3
+
dbeef3
 		pr->flags &= ~BLKID_FL_MODIF_BUFF;	/* be paranoid */
dbeef3
 
dbeef3
 		return blkid_probe_step_back(pr);
dbeef3
diff --git a/misc-utils/wipefs.c b/misc-utils/wipefs.c
dbeef3
index 78dc63ee7..f08a9ba4f 100644
dbeef3
--- a/misc-utils/wipefs.c
dbeef3
+++ b/misc-utils/wipefs.c
dbeef3
@@ -615,7 +615,9 @@ static int do_wipe(struct wipe_control *ctl)
dbeef3
 	if (need_force)
dbeef3
 		warnx(_("Use the --force option to force erase."));
dbeef3
 
dbeef3
-	fsync(blkid_probe_get_fd(pr));
dbeef3
+	if (fsync(blkid_probe_get_fd(pr)) != 0)
dbeef3
+		err(EXIT_FAILURE, _("%s: cannot flush modified buffers"),
dbeef3
+				ctl->devname);
dbeef3
 
dbeef3
 #ifdef BLKRRPART
dbeef3
 	if (reread && (mode & O_EXCL)) {
dbeef3
@@ -635,7 +637,9 @@ static int do_wipe(struct wipe_control *ctl)
dbeef3
 	}
dbeef3
 #endif
dbeef3
 
dbeef3
-	close(blkid_probe_get_fd(pr));
dbeef3
+	if (close(blkid_probe_get_fd(pr)) != 0)
dbeef3
+		err(EXIT_FAILURE, _("%s: close device failed"), ctl->devname);
dbeef3
+
dbeef3
 	blkid_free_probe(pr);
dbeef3
 	free(backup);
dbeef3
 	return 0;
dbeef3
-- 
dbeef3
2.36.1
dbeef3