File blockdev-allow-for-larger-values-for-start-sector.patch of Package python3-libmount.22201

From d73a71840b881d5af0f7f16a82f0b910f0b616c0 Mon Sep 17 00:00:00 2001
From: Thomas Abraham <tabraham@suse.com>
Date: Thu, 22 Jul 2021 15:43:13 -0400
Subject: [PATCH] blockdev: allow for larger values for start sector

commit 9147d2ad8a ("blockdev: Don't fail on missing start sector") limits
the size of the start sector to 10 digits.

Multi-terrabyte devices can have partitions with a start sector larger than
10 digits, which will cause an sprintf() to abort due to overflowing the buffer.

It causes:
  # blockdev --report /dev/sda4
  RO    RA   SSZ   BSZ   StartSec            Size   Device
  *** buffer overflow detected ***: terminated
  Aborted (core dumped)
---
 disk-utils/blockdev.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/disk-utils/blockdev.c b/disk-utils/blockdev.c
index 4fd5b8495..3c5be173a 100644
--- a/disk-utils/blockdev.c
+++ b/disk-utils/blockdev.c
@@ -456,7 +456,7 @@ static void report_device(char *device, int quiet)
 	long ra;
 	unsigned long long bytes;
 	uint64_t start = 0;
-	char start_str[11] = { "\0" };
+	char start_str[16] = { "\0" };
 	struct stat st;
 
 	fd = open(device, O_RDONLY | O_NONBLOCK);
@@ -478,13 +478,13 @@ static void report_device(char *device, int quiet)
 		    disk != st.st_rdev) {
 
 			if (ul_path_read_u64(pc, &start, "start") != 0)
-				/* TRANSLATORS: Start sector not available. Max. 10 letters. */
-				sprintf(start_str, "%10s", _("N/A"));
+				/* TRANSLATORS: Start sector not available. Max. 15 letters. */
+				sprintf(start_str, "%15s", _("N/A"));
 		}
 		ul_unref_path(pc);
 	}
 	if (!*start_str)
-		sprintf(start_str, "%10ju", start);
+		sprintf(start_str, "%15ju", start);
 
 	if (ioctl(fd, BLKROGET, &ro) == 0 &&
 	    ioctl(fd, BLKRAGET, &ra) == 0 &&
@@ -503,5 +503,5 @@ static void report_device(char *device, int quiet)
 
 static void report_header(void)
 {
-	printf(_("RO    RA   SSZ   BSZ   StartSec            Size   Device\n"));
+	printf(_("RO    RA   SSZ   BSZ        StartSec            Size   Device\n"));
 }
-- 
2.26.2

openSUSE Build Service is sponsored by