From: Thomas Abraham Date: Thu, 22 Jul 2021 19:43:13 +0000 (-0400) Subject: blockdev: allow for larger values for start sector X-Git-Tag: v2.37.2~25 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b5a4d57a5c9cca7dae3463a0dba3e194d2affde9;p=thirdparty%2Futil-linux.git 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) --- diff --git a/disk-utils/blockdev.c b/disk-utils/blockdev.c index 4fd5b8495a..3c5be173a1 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")); }