diff --git a/Add-check-to-resolve-uname26-version-test-failed.patch b/Add-check-to-resolve-uname26-version-test-failed.patch new file mode 100644 index 0000000000000000000000000000000000000000..193c6ede090f9e23e675fd4980dd7868a34576bf --- /dev/null +++ b/Add-check-to-resolve-uname26-version-test-failed.patch @@ -0,0 +1,34 @@ +From 72466ac801928c205604b99fe01f830809bda930 Mon Sep 17 00:00:00 2001 +From: Liquor +Date: Thu, 17 Dec 2020 15:04:56 +0800 +Subject: [PATCH] Add check to resolve uname26-version test failed + +The uname command is modified in packages uname-build-checks, +but the uname26-version test case needs to use the uname -r query +result.As a result,the test fails. +So we add a judgment to check whether uname-build-checks is installed. +--- + tests/ts/misc/setarch | 7 ++++++- + 1 file changed, 6 insertions(+), 1 deletion(-) + +diff --git a/tests/ts/misc/setarch b/tests/ts/misc/setarch +index 7c99cca..25d02c1 100755 +--- a/tests/ts/misc/setarch ++++ b/tests/ts/misc/setarch +@@ -77,7 +77,12 @@ ts_finalize_subtest "$finmsg" + # conditional subtest + if [ "$uname26_seems_supported" = "yes" ]; then + ts_init_subtest uname26-version +- tmp=$($TS_CMD_SETARCH $ARCH --uname-2.6 uname -r) ++ rpm -qa | grep -q "uname-build-checks" ++ if [ $? -eq 0 ]; then ++ tmp=$($TS_CMD_SETARCH $ARCH --uname-2.6 uname.bin -r) ++ else ++ tmp=$($TS_CMD_SETARCH $ARCH --uname-2.6 uname -r) ++ fi + if echo "$tmp" | grep -q "^2\.6\."; then + echo "kernel version changed to 2.6" >> $TS_OUTPUT + else +-- +2.27.0 + diff --git a/backpaort-fix-rounding-in-size_to_human_string.patch b/backpaort-fix-rounding-in-size_to_human_string.patch new file mode 100644 index 0000000000000000000000000000000000000000..2c2013e4d44b9d5faefb467536daa1ea6c18b02c --- /dev/null +++ b/backpaort-fix-rounding-in-size_to_human_string.patch @@ -0,0 +1,156 @@ +From b38c20e13a51acb7e3bb388e9cc17d5fc905e7d9 Mon Sep 17 00:00:00 2001 +From: Karel Zak +Date: Wed, 15 Apr 2020 15:01:12 +0200 +Subject: [PATCH] ilib/strutils: fix rounding in size_to_human_string() + +Thanks to bub75 for the idea. + +The patch adds SIZE_DECIMAL_2DIGITS into regression tests. + +Addresses: https://github.com/karelzak/util-linux/issues/998 +Signed-off-by: Karel Zak +--- + lib/strutils.c | 43 +++++++++++++++++++++-------- + tests/expected/misc/strtosize | 52 +++++++++++++++++------------------ + 2 files changed, 58 insertions(+), 37 deletions(-) + +diff --git a/lib/strutils.c b/lib/strutils.c +index be404e703b..ccf48919bd 100644 +--- a/lib/strutils.c ++++ b/lib/strutils.c +@@ -602,24 +602,41 @@ char *size_to_human_string(int options, uint64_t bytes) + + /* round */ + if (frac) { ++ /* get 3 digits after decimal point */ ++ frac = (frac * 1000) / (1ULL << exp); ++ + if (options & SIZE_DECIMAL_2DIGITS) { +- frac = (frac / (1ULL << (exp - 10)) + 5) / 10; +- if (frac % 10 == 0) +- frac /= 10; /* convert N.90 to N.9 */ ++ /* round 4/5 and keep 2 digits after decimal point */ ++ frac = (frac + 5) / 10 ; + } else { +- frac = (frac / (1ULL << (exp - 10)) + 50) / 100; +- if (frac == 10) +- dec++, frac = 0; ++ /* round 4/5 and keep 1 digit after decimal point */ ++ frac = ((frac + 50) / 100) * 10 ; ++ } ++ ++ /* rounding could have overflowed */ ++ if (frac == 100) { ++ dec++; ++ frac = 0; + } + } + + if (frac) { + struct lconv const *l = localeconv(); + char *dp = l ? l->decimal_point : NULL; ++ int len; + + if (!dp || !*dp) + dp = "."; +- snprintf(buf, sizeof(buf), "%d%s%" PRIu64 "%s", dec, dp, frac, suffix); ++ ++ len = snprintf(buf, sizeof(buf), "%d%s%02" PRIu64, dec, dp, frac); ++ if (len > 0 && (size_t) len < sizeof(buf)) { ++ /* remove potential extraneous zero */ ++ if (buf[len - 1] == '0') ++ buf[len--] = '\0'; ++ /* append suffix */ ++ xstrncpy(buf+len, suffix, sizeof(buf) - len); ++ } else ++ *buf = '\0'; /* snprintf error */ + } else + snprintf(buf, sizeof(buf), "%d%s", dec, suffix); + +@@ -1051,7 +1068,7 @@ static int test_strdup_to_member(int argc, char *argv[]) + static int test_strutils_sizes(int argc, char *argv[]) + { + uintmax_t size = 0; +- char *hum, *hum2; ++ char *hum1, *hum2, *hum3; + + if (argc < 2) + return EXIT_FAILURE; +@@ -1059,13 +1076,17 @@ static int test_strutils_sizes(int argc, char *argv[]) + if (strtosize(argv[1], &size)) + errx(EXIT_FAILURE, "invalid size '%s' value", argv[1]); + +- hum = size_to_human_string(SIZE_SUFFIX_1LETTER, size); ++ hum1 = size_to_human_string(SIZE_SUFFIX_1LETTER, size); + hum2 = size_to_human_string(SIZE_SUFFIX_3LETTER | + SIZE_SUFFIX_SPACE, size); ++ hum3 = size_to_human_string(SIZE_SUFFIX_3LETTER | ++ SIZE_SUFFIX_SPACE | ++ SIZE_DECIMAL_2DIGITS, size); + +- printf("%25s : %20ju : %8s : %12s\n", argv[1], size, hum, hum2); +- free(hum); ++ printf("%25s : %20ju : %8s : %12s : %13s\n", argv[1], size, hum1, hum2, hum3); ++ free(hum1); + free(hum2); ++ free(hum3); + + return EXIT_SUCCESS; + } +diff --git a/tests/expected/misc/strtosize b/tests/expected/misc/strtosize +index 8d93e142d3..abda45a575 100644 +--- a/tests/expected/misc/strtosize ++++ b/tests/expected/misc/strtosize +@@ -1,26 +1,26 @@ +- 0 : 0 : 0B : 0 B +- 1 : 1 : 1B : 1 B +- 123 : 123 : 123B : 123 B +- 18446744073709551615 : 18446744073709551615 : 16E : 16 EiB +- 1K : 1024 : 1K : 1 KiB +- 1KiB : 1024 : 1K : 1 KiB +- 1M : 1048576 : 1M : 1 MiB +- 1MiB : 1048576 : 1M : 1 MiB +- 1G : 1073741824 : 1G : 1 GiB +- 1GiB : 1073741824 : 1G : 1 GiB +- 1T : 1099511627776 : 1T : 1 TiB +- 1TiB : 1099511627776 : 1T : 1 TiB +- 1P : 1125899906842624 : 1P : 1 PiB +- 1PiB : 1125899906842624 : 1P : 1 PiB +- 1E : 1152921504606846976 : 1E : 1 EiB +- 1EiB : 1152921504606846976 : 1E : 1 EiB +- 1KB : 1000 : 1000B : 1000 B +- 1MB : 1000000 : 976.6K : 976.6 KiB +- 1GB : 1000000000 : 953.7M : 953.7 MiB +- 1TB : 1000000000000 : 931.3G : 931.3 GiB +- 1PB : 1000000000000000 : 909.5T : 909.5 TiB +- 1EB : 1000000000000000000 : 888.2P : 888.2 PiB +- 1 : 1 : 1B : 1 B +- 0x0a : 10 : 10B : 10 B +- 0xff00 : 65280 : 63.8K : 63.8 KiB +- 0x80000000 : 2147483648 : 2G : 2 GiB ++ 0 : 0 : 0B : 0 B : 0 B ++ 1 : 1 : 1B : 1 B : 1 B ++ 123 : 123 : 123B : 123 B : 123 B ++ 18446744073709551615 : 18446744073709551615 : 15E : 15 EiB : 15.01 EiB ++ 1K : 1024 : 1K : 1 KiB : 1 KiB ++ 1KiB : 1024 : 1K : 1 KiB : 1 KiB ++ 1M : 1048576 : 1M : 1 MiB : 1 MiB ++ 1MiB : 1048576 : 1M : 1 MiB : 1 MiB ++ 1G : 1073741824 : 1G : 1 GiB : 1 GiB ++ 1GiB : 1073741824 : 1G : 1 GiB : 1 GiB ++ 1T : 1099511627776 : 1T : 1 TiB : 1 TiB ++ 1TiB : 1099511627776 : 1T : 1 TiB : 1 TiB ++ 1P : 1125899906842624 : 1P : 1 PiB : 1 PiB ++ 1PiB : 1125899906842624 : 1P : 1 PiB : 1 PiB ++ 1E : 1152921504606846976 : 1E : 1 EiB : 1 EiB ++ 1EiB : 1152921504606846976 : 1E : 1 EiB : 1 EiB ++ 1KB : 1000 : 1000B : 1000 B : 1000 B ++ 1MB : 1000000 : 976.6K : 976.6 KiB : 976.56 KiB ++ 1GB : 1000000000 : 953.7M : 953.7 MiB : 953.67 MiB ++ 1TB : 1000000000000 : 931.3G : 931.3 GiB : 931.32 GiB ++ 1PB : 1000000000000000 : 909.5T : 909.5 TiB : 909.49 TiB ++ 1EB : 1000000000000000000 : 888.2P : 888.2 PiB : 888.18 PiB ++ 1 : 1 : 1B : 1 B : 1 B ++ 0x0a : 10 : 10B : 10 B : 10 B ++ 0xff00 : 65280 : 63.8K : 63.8 KiB : 63.75 KiB ++ 0x80000000 : 2147483648 : 2G : 2 GiB : 2 GiB diff --git a/backpaort-fix-uint64_t-overflow.patch b/backpaort-fix-uint64_t-overflow.patch new file mode 100644 index 0000000000000000000000000000000000000000..603507d438e47cf1b29d83c74e4fc02e4e974aeb --- /dev/null +++ b/backpaort-fix-uint64_t-overflow.patch @@ -0,0 +1,41 @@ +From f12d5ad279f248b2fb63394331010f2c835b1a74 Mon Sep 17 00:00:00 2001 +From: Karel Zak +Date: Fri, 17 Apr 2020 10:21:56 +0200 +Subject: [PATCH] lib/strutils: fix uint64_t overflow + +Addresses: https://github.com/karelzak/util-linux/issues/998 +Signed-off-by: Karel Zak +--- + lib/strutils.c | 5 ++++- + tests/expected/misc/strtosize | 2 +- + 2 files changed, 5 insertions(+), 2 deletions(-) + +diff --git a/lib/strutils.c b/lib/strutils.c +index ccf48919bd..b76ab99520 100644 +--- a/lib/strutils.c ++++ b/lib/strutils.c +@@ -603,7 +603,10 @@ char *size_to_human_string(int options, uint64_t bytes) + /* round */ + if (frac) { + /* get 3 digits after decimal point */ +- frac = (frac * 1000) / (1ULL << exp); ++ if (frac >= UINT64_MAX / 1000) ++ frac = ((frac / 1024) * 1000) / (1ULL << (exp - 10)) ; ++ else ++ frac = (frac * 1000) / (1ULL << (exp)) ; + + if (options & SIZE_DECIMAL_2DIGITS) { + /* round 4/5 and keep 2 digits after decimal point */ +diff --git a/tests/expected/misc/strtosize b/tests/expected/misc/strtosize +index abda45a575..0f912f7229 100644 +--- a/tests/expected/misc/strtosize ++++ b/tests/expected/misc/strtosize +@@ -1,7 +1,7 @@ + 0 : 0 : 0B : 0 B : 0 B + 1 : 1 : 1B : 1 B : 1 B + 123 : 123 : 123B : 123 B : 123 B +- 18446744073709551615 : 18446744073709551615 : 15E : 15 EiB : 15.01 EiB ++ 18446744073709551615 : 18446744073709551615 : 16E : 16 EiB : 16 EiB + 1K : 1024 : 1K : 1 KiB : 1 KiB + 1KiB : 1024 : 1K : 1 KiB : 1 KiB + 1M : 1048576 : 1M : 1 MiB : 1 MiB diff --git a/backpaort-update-fdisk-outputs-due-to-sizes-rounding-change.patch b/backpaort-update-fdisk-outputs-due-to-sizes-rounding-change.patch new file mode 100644 index 0000000000000000000000000000000000000000..28cb8b8549849c474d2b30ccf8ed393518ec9bfa --- /dev/null +++ b/backpaort-update-fdisk-outputs-due-to-sizes-rounding-change.patch @@ -0,0 +1,290 @@ +From 316617e84848da418aee413abe1d26a2f6a8fde7 Mon Sep 17 00:00:00 2001 +From: Karel Zak +Date: Thu, 16 Apr 2020 12:19:16 +0200 +Subject: [PATCH] tests: update fdisk outputs due to sizes rounding change + +References: b38c20e13a51acb7e3bb388e9cc17d5fc905e7d9 +Signed-off-by: Karel Zak +--- + tests/expected/blkid/md-raid0-whole | 2 +- + tests/expected/blkid/md-raid1-whole | 2 +- + tests/expected/fdisk/align-512-4K-md | 2 +- + tests/expected/fdisk/bsd_0_64.BE | 4 ++-- + tests/expected/fdisk/bsd_0_64.LE | 4 ++-- + tests/expected/fdisk/bsd_0_64_alpha.LE | 4 ++-- + tests/expected/fdisk/bsd_1_0.BE | 4 ++-- + tests/expected/fdisk/bsd_1_0.LE | 4 ++-- + tests/expected/fdisk/mbr-dos-mode | 10 +++++----- + tests/expected/fdisk/sunlabel | 18 +++++++++--------- + tests/expected/partx/partx-image-dos+bsd | 2 +- + 11 files changed, 28 insertions(+), 28 deletions(-) + +diff --git a/tests/expected/blkid/md-raid0-whole b/tests/expected/blkid/md-raid0-whole +index cc0b17f..475eb05 100644 +--- a/tests/expected/blkid/md-raid0-whole ++++ b/tests/expected/blkid/md-raid0-whole +@@ -19,7 +19,7 @@ Command (m for help): Partition type + Select (default p): Partition number (2-4, default 2): First sector (22528-204543, default 22528): Last sector, +/-sectors or +/-size{K,M,G,T,P} (22528-204543, default 204543): + Created a new . + +-Command (m for help): Disk : 99.9 MiB, 104726528 bytes, 204544 sectors ++Command (m for help): Disk : 99.88 MiB, 104726528 bytes, 204544 sectors + Units: sectors of 1 * 512 = 512 bytes + Sector size (logical/physical): 512 bytes / 512 bytes + I/O size (minimum/optimal): 65536 bytes / bytes +diff --git a/tests/expected/blkid/md-raid1-whole b/tests/expected/blkid/md-raid1-whole +index 6334ae1..891778c 100644 +--- a/tests/expected/blkid/md-raid1-whole ++++ b/tests/expected/blkid/md-raid1-whole +@@ -19,7 +19,7 @@ Command (m for help): Partition type + Select (default p): Partition number (2-4, default 2): First sector (22528-102271, default 22528): Last sector, +/-sectors or +/-size{K,M,G,T,P} (22528-102271, default 102271): + Created a new . + +-Command (m for help): Disk /dev/md8: 49.96 MiB, 52363264 bytes, 102272 sectors ++Command (m for help): Disk /dev/md8: 49.94 MiB, 52363264 bytes, 102272 sectors + Units: sectors of 1 * 512 = 512 bytes + Sector size (logical/physical): 512 bytes / 512 bytes + I/O size (minimum/optimal): bytes / bytes +diff --git a/tests/expected/fdisk/align-512-4K-md b/tests/expected/fdisk/align-512-4K-md +index ce9b3e7..c69e72f 100644 +--- a/tests/expected/fdisk/align-512-4K-md ++++ b/tests/expected/fdisk/align-512-4K-md +@@ -59,7 +59,7 @@ Command (m for help): Partition type + Select (default p): Partition number (2-4, default 2): First sector (22528-97791, default 22528): Last sector, +/-sectors or +/-size{K,M,G,T,P} (22528-97791, default 97791): + Created a new . + +-Command (m for help): Disk : 47.77 MiB, 50069504 bytes, 97792 sectors ++Command (m for help): Disk : 47.75 MiB, 50069504 bytes, 97792 sectors + Units: sectors of 1 * 512 = 512 bytes + Sector size (logical/physical): 512 bytes / 4096 bytes + I/O size (minimum/optimal): 65536 bytes / bytes +diff --git a/tests/expected/fdisk/bsd_0_64.BE b/tests/expected/fdisk/bsd_0_64.BE +index 3a79c49..fd78576 100644 +--- a/tests/expected/fdisk/bsd_0_64.BE ++++ b/tests/expected/fdisk/bsd_0_64.BE +@@ -132,7 +132,7 @@ Disklabel type: bsd + + Slice Start End Sectors Size Type Fsize Bsize Cpg + c 4096 20479 16384 8M unused 0 0 0 +-d 0 16064 16065 7.9M unused 0 0 0 ++d 0 16064 16065 7.8M unused 0 0 0 + + Partition table entries are not in disk order. + +@@ -186,7 +186,7 @@ Disklabel type: bsd + Slice Start End Sectors Size Type Fsize Bsize Cpg + a 4096 6144 2049 1M 4.2BSD 0 0 0 + c 4096 20479 16384 8M unused 0 0 0 +-d 0 16064 16065 7.9M unused 0 0 0 ++d 0 16064 16065 7.8M unused 0 0 0 + + Partition table entries are not in disk order. + +diff --git a/tests/expected/fdisk/bsd_0_64.LE b/tests/expected/fdisk/bsd_0_64.LE +index d673d04..fe6e042 100644 +--- a/tests/expected/fdisk/bsd_0_64.LE ++++ b/tests/expected/fdisk/bsd_0_64.LE +@@ -132,7 +132,7 @@ Disklabel type: bsd + + Slice Start End Sectors Size Type Fsize Bsize Cpg + c 4096 20479 16384 8M unused 0 0 0 +-d 0 16064 16065 7.9M unused 0 0 0 ++d 0 16064 16065 7.8M unused 0 0 0 + + Partition table entries are not in disk order. + +@@ -186,7 +186,7 @@ Disklabel type: bsd + Slice Start End Sectors Size Type Fsize Bsize Cpg + a 4096 6144 2049 1M 4.2BSD 0 0 0 + c 4096 20479 16384 8M unused 0 0 0 +-d 0 16064 16065 7.9M unused 0 0 0 ++d 0 16064 16065 7.8M unused 0 0 0 + + Partition table entries are not in disk order. + +diff --git a/tests/expected/fdisk/bsd_0_64_alpha.LE b/tests/expected/fdisk/bsd_0_64_alpha.LE +index 1c2a368..a675e98 100644 +--- a/tests/expected/fdisk/bsd_0_64_alpha.LE ++++ b/tests/expected/fdisk/bsd_0_64_alpha.LE +@@ -134,7 +134,7 @@ Disklabel type: bsd + + Slice Start End Sectors Size Type Fsize Bsize Cpg + c 4096 20479 16384 8M unused 0 0 0 +-d 0 16064 16065 7.9M unused 0 0 0 ++d 0 16064 16065 7.8M unused 0 0 0 + + Partition table entries are not in disk order. + +@@ -190,7 +190,7 @@ Disklabel type: bsd + Slice Start End Sectors Size Type Fsize Bsize Cpg + a 4096 6144 2049 1M 4.2BSD 0 0 0 + c 4096 20479 16384 8M unused 0 0 0 +-d 0 16064 16065 7.9M unused 0 0 0 ++d 0 16064 16065 7.8M unused 0 0 0 + + Partition table entries are not in disk order. + +diff --git a/tests/expected/fdisk/bsd_1_0.BE b/tests/expected/fdisk/bsd_1_0.BE +index 2c46abd..13a5cfe 100644 +--- a/tests/expected/fdisk/bsd_1_0.BE ++++ b/tests/expected/fdisk/bsd_1_0.BE +@@ -132,7 +132,7 @@ Disklabel type: bsd + + Slice Start End Sectors Size Type Fsize Bsize Cpg + c 4096 20479 16384 8M unused 0 0 0 +-d 0 16064 16065 7.9M unused 0 0 0 ++d 0 16064 16065 7.8M unused 0 0 0 + + Partition table entries are not in disk order. + +@@ -186,7 +186,7 @@ Disklabel type: bsd + Slice Start End Sectors Size Type Fsize Bsize Cpg + a 4096 6144 2049 1M 4.2BSD 0 0 0 + c 4096 20479 16384 8M unused 0 0 0 +-d 0 16064 16065 7.9M unused 0 0 0 ++d 0 16064 16065 7.8M unused 0 0 0 + + Partition table entries are not in disk order. + +diff --git a/tests/expected/fdisk/bsd_1_0.LE b/tests/expected/fdisk/bsd_1_0.LE +index 5f3b838..b6e3661 100644 +--- a/tests/expected/fdisk/bsd_1_0.LE ++++ b/tests/expected/fdisk/bsd_1_0.LE +@@ -132,7 +132,7 @@ Disklabel type: bsd + + Slice Start End Sectors Size Type Fsize Bsize Cpg + c 4096 20479 16384 8M unused 0 0 0 +-d 0 16064 16065 7.9M unused 0 0 0 ++d 0 16064 16065 7.8M unused 0 0 0 + + Partition table entries are not in disk order. + +@@ -186,7 +186,7 @@ Disklabel type: bsd + Slice Start End Sectors Size Type Fsize Bsize Cpg + a 4096 6144 2049 1M 4.2BSD 0 0 0 + c 4096 20479 16384 8M unused 0 0 0 +-d 0 16064 16065 7.9M unused 0 0 0 ++d 0 16064 16065 7.8M unused 0 0 0 + + Partition table entries are not in disk order. + +diff --git a/tests/expected/fdisk/mbr-dos-mode b/tests/expected/fdisk/mbr-dos-mode +index 6560099..5bc1fbf 100644 +--- a/tests/expected/fdisk/mbr-dos-mode ++++ b/tests/expected/fdisk/mbr-dos-mode +@@ -98,7 +98,7 @@ Create logical partitions + a1cd6708e4a6d2e5f6bc9d5c0da0cf3b mbr-dos-mode.img + + ---layout---------- +-Disk : 54.93 MiB, 57577472 bytes, 112456 sectors ++Disk : 54.91 MiB, 57577472 bytes, 112456 sectors + Geometry: 255 heads, 63 sectors/track, 1024 cylinders + Units: cylinders of 16065 * 512 = 8225280 bytes + Sector size (logical/physical): 512 bytes / 512 bytes +@@ -119,7 +119,7 @@ Delete logical partitions + 4c6937d529ace5661fb82efb9394154a mbr-dos-mode.img + + ---layout---------- +-Disk : 54.93 MiB, 57577472 bytes, 112456 sectors ++Disk : 54.91 MiB, 57577472 bytes, 112456 sectors + Geometry: 255 heads, 63 sectors/track, 1024 cylinders + Units: cylinders of 16065 * 512 = 8225280 bytes + Sector size (logical/physical): 512 bytes / 512 bytes +@@ -137,7 +137,7 @@ Create another logical partition + 9589eaaed698d2402945ab3e513c1eb4 mbr-dos-mode.img + + ---layout---------- +-Disk : 54.93 MiB, 57577472 bytes, 112456 sectors ++Disk : 54.91 MiB, 57577472 bytes, 112456 sectors + Geometry: 255 heads, 63 sectors/track, 1024 cylinders + Units: cylinders of 16065 * 512 = 8225280 bytes + Sector size (logical/physical): 512 bytes / 512 bytes +@@ -158,7 +158,7 @@ Delete primary partition + 1e6d646e5df66a2664cfbbb13fa9a08a mbr-dos-mode.img + + ---layout---------- +-Disk : 54.93 MiB, 57577472 bytes, 112456 sectors ++Disk : 54.91 MiB, 57577472 bytes, 112456 sectors + Geometry: 255 heads, 63 sectors/track, 1024 cylinders + Units: cylinders of 16065 * 512 = 8225280 bytes + Sector size (logical/physical): 512 bytes / 512 bytes +@@ -178,7 +178,7 @@ Delete extended partition + fc3cdb12326656d7996b09b6f76973e7 mbr-dos-mode.img + + ---layout---------- +-Disk : 54.93 MiB, 57577472 bytes, 112456 sectors ++Disk : 54.91 MiB, 57577472 bytes, 112456 sectors + Geometry: 255 heads, 63 sectors/track, 1024 cylinders + Units: cylinders of 16065 * 512 = 8225280 bytes + Sector size (logical/physical): 512 bytes / 512 bytes +diff --git a/tests/expected/fdisk/sunlabel b/tests/expected/fdisk/sunlabel +index 5ada4fa..2f47208 100644 +--- a/tests/expected/fdisk/sunlabel ++++ b/tests/expected/fdisk/sunlabel +@@ -17,8 +17,8 @@ Sector size (logical/physical): 512 bytes / 512 bytes + I/O size (minimum/optimal): 512 bytes / bytes + Disklabel type: sun + +-Device Start End Cylinders Size Id Type Flags +-1 1 128 129 4M 83 Linux native ++Device Start End Cylinders Size Id Type Flags ++1 1 128 129 3.9M 83 Linux native + Set partition sysid + df75defdb97fbd56222aed18631a22d0 sunlabel.img + Disk : 10 MiB, 10485760 bytes, 20480 sectors +@@ -28,8 +28,8 @@ Sector size (logical/physical): 512 bytes / 512 bytes + I/O size (minimum/optimal): 512 bytes / bytes + Disklabel type: sun + +-Device Start End Cylinders Size Id Type Flags +-1 1 128 129 4M 4 SunOS usr ++Device Start End Cylinders Size Id Type Flags ++1 1 128 129 3.9M 4 SunOS usr + Set first partition readonly + da23f66698d9a553162887621d4c7490 sunlabel.img + Disk : 10 MiB, 10485760 bytes, 20480 sectors +@@ -39,8 +39,8 @@ Sector size (logical/physical): 512 bytes / 512 bytes + I/O size (minimum/optimal): 512 bytes / bytes + Disklabel type: sun + +-Device Start End Cylinders Size Id Type Flags +-1 1 128 129 4M 4 SunOS usr r ++Device Start End Cylinders Size Id Type Flags ++1 1 128 129 3.9M 4 SunOS usr r + Set first partition mountable + 3ab76e8491b103eab52b2ae1856c1e30 sunlabel.img + Disk : 10 MiB, 10485760 bytes, 20480 sectors +@@ -50,8 +50,8 @@ Sector size (logical/physical): 512 bytes / 512 bytes + I/O size (minimum/optimal): 512 bytes / bytes + Disklabel type: sun + +-Device Start End Cylinders Size Id Type Flags +-1 1 128 129 4M 4 SunOS usr ur ++Device Start End Cylinders Size Id Type Flags ++1 1 128 129 3.9M 4 SunOS usr ur + Create second partition + + Welcome to fdisk . +@@ -74,7 +74,7 @@ I/O size (minimum/optimal): 512 bytes / bytes + Disklabel type: sun + + Device Start End Cylinders Size Id Type Flags +-1 1 128 129 4M 4 SunOS usr ur ++1 1 128 129 3.9M 4 SunOS usr ur + 2 129 325 198 6.1M 83 Linux native + Delete all partitions + 502ba7a0cfdce2849c3a99881f0590c3 sunlabel.img +diff --git a/tests/expected/partx/partx-image-dos+bsd b/tests/expected/partx/partx-image-dos+bsd +index 379633d..ae5f314 100644 +--- a/tests/expected/partx/partx-image-dos+bsd ++++ b/tests/expected/partx/partx-image-dos+bsd +@@ -1,5 +1,5 @@ + NR START END SECTORS SIZE NAME UUID +- 1 32 7679 7648 3.8M 8f8378c0-01 ++ 1 32 7679 7648 3.7M 8f8378c0-01 + 2 7680 16383 8704 4.3M 8f8378c0-02 + 5 7936 12799 4864 2.4M + 6 12544 16127 3584 1.8M +-- +2.27.0 + diff --git a/backport-CVE-2021-37600.patch b/backport-CVE-2021-37600.patch new file mode 100644 index 0000000000000000000000000000000000000000..139656e7ca6500cb73b8de369eff78e6b71eb135 --- /dev/null +++ b/backport-CVE-2021-37600.patch @@ -0,0 +1,25 @@ +From 1c9143d0c1f979c3daf10e1c37b5b1e916c22a1c Mon Sep 17 00:00:00 2001 +From: Karel Zak +Date: Tue, 27 Jul 2021 11:58:31 +0200 +Subject: [PATCH] sys-utils/ipcutils: be careful when call calloc() for uint64 + nmembs + +Fix: https://github.com/karelzak/util-linux/issues/1395 +Signed-off-by: Karel Zak +--- + sys-utils/ipcutils.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/sys-utils/ipcutils.c b/sys-utils/ipcutils.c +index e784c4dcb9..18868cfd38 100644 +--- a/sys-utils/ipcutils.c ++++ b/sys-utils/ipcutils.c +@@ -218,7 +218,7 @@ static void get_sem_elements(struct sem_data *p) + { + size_t i; + +- if (!p || !p->sem_nsems || p->sem_perm.id < 0) ++ if (!p || !p->sem_nsems || p->sem_nsems > SIZE_MAX || p->sem_perm.id < 0) + return; + + p->elements = xcalloc(p->sem_nsems, sizeof(struct sem_elem)); diff --git a/backport-CVE-2021-3995.patch b/backport-CVE-2021-3995.patch new file mode 100644 index 0000000000000000000000000000000000000000..cd58532ee8dbac39e4db3c3e71d59dbfb23f1f93 --- /dev/null +++ b/backport-CVE-2021-3995.patch @@ -0,0 +1,138 @@ +From f3db9bd609494099f0c1b95231c5dfe383346929 Mon Sep 17 00:00:00 2001 +From: Karel Zak +Date: Wed, 24 Nov 2021 13:53:25 +0100 +Subject: [PATCH] libmount: fix UID check for FUSE umount [CVE-2021-3995] + +Improper UID check allows an unprivileged user to unmount FUSE +filesystems of users with similar UID. + +Signed-off-by: Karel Zak +Reference:https://github.com/util-linux/util-linux/commit/f3db9bd609494099f0c1b95231c5dfe383346929 +Conflict:NA +--- + include/strutils.h | 2 +- + libmount/src/context_umount.c | 13 +++-------- + libmount/src/mountP.h | 1 + + libmount/src/optstr.c | 42 +++++++++++++++++++++++++++++++++++ + 4 files changed, 47 insertions(+), 11 deletions(-) + +diff --git a/include/strutils.h b/include/strutils.h +index 4b3182f..50e493a 100644 +--- a/include/strutils.h ++++ b/include/strutils.h +@@ -88,8 +88,8 @@ static inline char *mem2strcpy(char *dest, const void *src, size_t n, size_t nma + if (n + 1 > nmax) + n = nmax - 1; + ++ memset(dest, '\0', nmax); + memcpy(dest, src, n); +- dest[nmax-1] = '\0'; + return dest; + } + +diff --git a/libmount/src/context_umount.c b/libmount/src/context_umount.c +index 94f824b..0d77fff 100644 +--- a/libmount/src/context_umount.c ++++ b/libmount/src/context_umount.c +@@ -393,10 +393,7 @@ static int is_fuse_usermount(struct libmnt_context *cxt, int *errsv) + struct libmnt_ns *ns_old; + const char *type = mnt_fs_get_fstype(cxt->fs); + const char *optstr; +- char *user_id = NULL; +- size_t sz; +- uid_t uid; +- char uidstr[sizeof(stringify_value(ULONG_MAX))]; ++ uid_t uid, entry_uid; + + *errsv = 0; + +@@ -414,10 +411,7 @@ static int is_fuse_usermount(struct libmnt_context *cxt, int *errsv) + if (!optstr) + return 0; + +- if (mnt_optstr_get_option(optstr, "user_id", &user_id, &sz) != 0) +- return 0; +- +- if (sz == 0 || user_id == NULL) ++ if (mnt_optstr_get_uid(optstr, "user_id", &entry_uid) != 0) + return 0; + + /* get current user */ +@@ -434,8 +428,7 @@ static int is_fuse_usermount(struct libmnt_context *cxt, int *errsv) + return 0; + } + +- snprintf(uidstr, sizeof(uidstr), "%lu", (unsigned long) uid); +- return strncmp(user_id, uidstr, sz) == 0; ++ return uid == entry_uid; + } + + /* +diff --git a/libmount/src/mountP.h b/libmount/src/mountP.h +index d8ba0ab..4a2ddb3 100644 +--- a/libmount/src/mountP.h ++++ b/libmount/src/mountP.h +@@ -401,6 +401,7 @@ extern const struct libmnt_optmap *mnt_optmap_get_entry( + const struct libmnt_optmap **mapent); + + /* optstr.c */ ++extern int mnt_optstr_get_uid(const char *optstr, const char *name, uid_t *uid); + extern int mnt_optstr_remove_option_at(char **optstr, char *begin, char *end); + extern int mnt_optstr_fix_gid(char **optstr, char *value, size_t valsz, char **next); + extern int mnt_optstr_fix_uid(char **optstr, char *value, size_t valsz, char **next); +diff --git a/libmount/src/optstr.c b/libmount/src/optstr.c +index eea952b..8a92c32 100644 +--- a/libmount/src/optstr.c ++++ b/libmount/src/optstr.c +@@ -1090,6 +1090,48 @@ int mnt_optstr_fix_user(char **optstr) + return rc; + } + ++/* ++ * Converts value from @optstr addressed by @name to uid. ++ * ++ * Returns: 0 on success, 1 if not found, <0 on error ++ */ ++int mnt_optstr_get_uid(const char *optstr, const char *name, uid_t *uid) ++{ ++ char *value = NULL; ++ size_t valsz = 0; ++ char buf[sizeof(stringify_value(UINT64_MAX))]; ++ int rc; ++ uint64_t num; ++ ++ assert(optstr); ++ assert(name); ++ assert(uid); ++ ++ rc = mnt_optstr_get_option(optstr, name, &value, &valsz); ++ if (rc != 0) ++ goto fail; ++ ++ if (valsz > sizeof(buf) - 1) { ++ rc = -ERANGE; ++ goto fail; ++ } ++ mem2strcpy(buf, value, valsz, sizeof(buf)); ++ ++ rc = ul_strtou64(buf, &num, 10); ++ if (rc != 0) ++ goto fail; ++ if (num > ULONG_MAX || (uid_t) num != num) { ++ rc = -ERANGE; ++ goto fail; ++ } ++ *uid = (uid_t) num; ++ ++ return 0; ++fail: ++ DBG(UTILS, ul_debug("failed to convert '%s'= to number [rc=%d]", name, rc)); ++ return rc; ++} ++ + /** + * mnt_match_options: + * @optstr: options string +-- +2.27.0 + diff --git a/backport-CVE-2021-3996.patch b/backport-CVE-2021-3996.patch new file mode 100644 index 0000000000000000000000000000000000000000..12b81e21bc1565bb7fbd4f4f1af6bc9ca11e83fa --- /dev/null +++ b/backport-CVE-2021-3996.patch @@ -0,0 +1,226 @@ +From 018a10907fa9885093f6d87401556932c2d8bd2b Mon Sep 17 00:00:00 2001 +From: Karel Zak +Date: Tue, 4 Jan 2022 10:54:20 +0100 +Subject: [PATCH] libmount: fix (deleted) suffix issue [CVE-2021-3996] + +This issue is related to parsing the /proc/self/mountinfo file allows an +unprivileged user to unmount other user's filesystems that are either +world-writable themselves or mounted in a world-writable directory. + +The support for "(deleted)" is no more necessary as the Linux kernel does +not use it in /proc/self/mountinfo and /proc/self/mount files anymore. + +Signed-off-by: Karel Zak +Reference:https://github.com/util-linux/util-linux/commit/018a10907fa9885093f6d87401556932c2d8bd2b +Conflict:NA +--- + libmount/src/tab_parse.c | 5 ----- + tests/expected/findmnt/filter-options | 1 - + tests/expected/findmnt/filter-options-nameval-neg | 3 +-- + tests/expected/findmnt/filter-types-neg | 1 - + tests/expected/findmnt/outputs-default | 3 +-- + tests/expected/findmnt/outputs-force-tree | 3 +-- + tests/expected/findmnt/outputs-kernel | 3 +-- + tests/expected/libmount/tabdiff-mount | 1 - + tests/expected/libmount/tabdiff-move | 1 - + tests/expected/libmount/tabdiff-remount | 1 - + tests/expected/libmount/tabdiff-umount | 1 - + tests/expected/libmount/tabfiles-parse-mountinfo | 11 ----------- + tests/expected/libmount/tabfiles-py-parse-mountinfo | 11 ----------- + tests/ts/findmnt/files/mountinfo | 1 - + tests/ts/findmnt/files/mountinfo-nonroot | 1 - + tests/ts/libmount/files/mountinfo | 1 - + 16 files changed, 4 insertions(+), 44 deletions(-) + +diff --git a/libmount/src/tab_parse.c b/libmount/src/tab_parse.c +index 3a2cc0d..eec9758 100644 +--- a/libmount/src/tab_parse.c ++++ b/libmount/src/tab_parse.c +@@ -225,11 +225,6 @@ static int mnt_parse_mountinfo_line(struct libmnt_fs *fs, const char *s) + goto fail; + } + +- /* remove "\040(deleted)" suffix */ +- p = (char *) endswith(fs->target, PATH_DELETED_SUFFIX); +- if (p && *p) +- *p = '\0'; +- + s = skip_separator(s); + + /* (6) vfs options (fs-independent) */ +diff --git a/tests/expected/findmnt/filter-options b/tests/expected/findmnt/filter-options +index 2606bce..97b0ead 100644 +--- a/tests/expected/findmnt/filter-options ++++ b/tests/expected/findmnt/filter-options +@@ -28,5 +28,4 @@ TARGET SOURCE FSTYPE OPTIONS + /home/kzak/.gvfs gvfs-fuse-daemon fuse.gvfs-fuse-daemon rw,nosuid,nodev,relatime,user_id=500,group_id=500 + /var/lib/nfs/rpc_pipefs sunrpc rpc_pipefs rw,relatime + /mnt/sounds //foo.home/bar/ cifs rw,relatime,unc=\\foo.home\bar,username=kzak,domain=SRGROUP,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.111.1,posixpaths,serverino,acl,rsize=16384,wsize=57344 +-/mnt/foo /fooooo bar rw,relatime + rc=0 +diff --git a/tests/expected/findmnt/filter-options-nameval-neg b/tests/expected/findmnt/filter-options-nameval-neg +index 5471d65..f0467ef 100644 +--- a/tests/expected/findmnt/filter-options-nameval-neg ++++ b/tests/expected/findmnt/filter-options-nameval-neg +@@ -29,6 +29,5 @@ TARGET SOURCE FSTYPE OPTIO + |-/home/kzak /dev/mapper/kzak-home ext4 rw,noatime,barrier=1,data=ordered + | `-/home/kzak/.gvfs gvfs-fuse-daemon fuse.gvfs-fuse-daemon rw,nosuid,nodev,relatime,user_id=500,group_id=500 + |-/var/lib/nfs/rpc_pipefs sunrpc rpc_pipefs rw,relatime +-|-/mnt/sounds //foo.home/bar/ cifs rw,relatime,unc=\\foo.home\bar,username=kzak,domain=SRGROUP,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.111.1,posixpaths,serverino,acl,rsize=16384,wsize=57344 +-`-/mnt/foo /fooooo bar rw,relatime ++`-/mnt/sounds //foo.home/bar/ cifs rw,relatime,unc=\\foo.home\bar,username=kzak,domain=SRGROUP,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.111.1,posixpaths,serverino,acl,rsize=16384,wsize=57344 + rc=0 +diff --git a/tests/expected/findmnt/filter-types-neg b/tests/expected/findmnt/filter-types-neg +index 2606bce..97b0ead 100644 +--- a/tests/expected/findmnt/filter-types-neg ++++ b/tests/expected/findmnt/filter-types-neg +@@ -28,5 +28,4 @@ TARGET SOURCE FSTYPE OPTIONS + /home/kzak/.gvfs gvfs-fuse-daemon fuse.gvfs-fuse-daemon rw,nosuid,nodev,relatime,user_id=500,group_id=500 + /var/lib/nfs/rpc_pipefs sunrpc rpc_pipefs rw,relatime + /mnt/sounds //foo.home/bar/ cifs rw,relatime,unc=\\foo.home\bar,username=kzak,domain=SRGROUP,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.111.1,posixpaths,serverino,acl,rsize=16384,wsize=57344 +-/mnt/foo /fooooo bar rw,relatime + rc=0 +diff --git a/tests/expected/findmnt/outputs-default b/tests/expected/findmnt/outputs-default +index 5949579..0159935 100644 +--- a/tests/expected/findmnt/outputs-default ++++ b/tests/expected/findmnt/outputs-default +@@ -30,6 +30,5 @@ TARGET SOURCE FSTYPE OPTIO + |-/home/kzak /dev/mapper/kzak-home ext4 rw,noatime,barrier=1,data=ordered + | `-/home/kzak/.gvfs gvfs-fuse-daemon fuse.gvfs-fuse-daemon rw,nosuid,nodev,relatime,user_id=500,group_id=500 + |-/var/lib/nfs/rpc_pipefs sunrpc rpc_pipefs rw,relatime +-|-/mnt/sounds //foo.home/bar/ cifs rw,relatime,unc=\\foo.home\bar,username=kzak,domain=SRGROUP,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.111.1,posixpaths,serverino,acl,rsize=16384,wsize=57344 +-`-/mnt/foo /fooooo bar rw,relatime ++`-/mnt/sounds //foo.home/bar/ cifs rw,relatime,unc=\\foo.home\bar,username=kzak,domain=SRGROUP,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.111.1,posixpaths,serverino,acl,rsize=16384,wsize=57344 + rc=0 +diff --git a/tests/expected/findmnt/outputs-force-tree b/tests/expected/findmnt/outputs-force-tree +index 5949579..0159935 100644 +--- a/tests/expected/findmnt/outputs-force-tree ++++ b/tests/expected/findmnt/outputs-force-tree +@@ -30,6 +30,5 @@ TARGET SOURCE FSTYPE OPTIO + |-/home/kzak /dev/mapper/kzak-home ext4 rw,noatime,barrier=1,data=ordered + | `-/home/kzak/.gvfs gvfs-fuse-daemon fuse.gvfs-fuse-daemon rw,nosuid,nodev,relatime,user_id=500,group_id=500 + |-/var/lib/nfs/rpc_pipefs sunrpc rpc_pipefs rw,relatime +-|-/mnt/sounds //foo.home/bar/ cifs rw,relatime,unc=\\foo.home\bar,username=kzak,domain=SRGROUP,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.111.1,posixpaths,serverino,acl,rsize=16384,wsize=57344 +-`-/mnt/foo /fooooo bar rw,relatime ++`-/mnt/sounds //foo.home/bar/ cifs rw,relatime,unc=\\foo.home\bar,username=kzak,domain=SRGROUP,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.111.1,posixpaths,serverino,acl,rsize=16384,wsize=57344 + rc=0 +diff --git a/tests/expected/findmnt/outputs-kernel b/tests/expected/findmnt/outputs-kernel +index 5949579..0159935 100644 +--- a/tests/expected/findmnt/outputs-kernel ++++ b/tests/expected/findmnt/outputs-kernel +@@ -30,6 +30,5 @@ TARGET SOURCE FSTYPE OPTIO + |-/home/kzak /dev/mapper/kzak-home ext4 rw,noatime,barrier=1,data=ordered + | `-/home/kzak/.gvfs gvfs-fuse-daemon fuse.gvfs-fuse-daemon rw,nosuid,nodev,relatime,user_id=500,group_id=500 + |-/var/lib/nfs/rpc_pipefs sunrpc rpc_pipefs rw,relatime +-|-/mnt/sounds //foo.home/bar/ cifs rw,relatime,unc=\\foo.home\bar,username=kzak,domain=SRGROUP,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.111.1,posixpaths,serverino,acl,rsize=16384,wsize=57344 +-`-/mnt/foo /fooooo bar rw,relatime ++`-/mnt/sounds //foo.home/bar/ cifs rw,relatime,unc=\\foo.home\bar,username=kzak,domain=SRGROUP,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.111.1,posixpaths,serverino,acl,rsize=16384,wsize=57344 + rc=0 +diff --git a/tests/expected/libmount/tabdiff-mount b/tests/expected/libmount/tabdiff-mount +index 420aeac..3c18f8d 100644 +--- a/tests/expected/libmount/tabdiff-mount ++++ b/tests/expected/libmount/tabdiff-mount +@@ -1,3 +1,2 @@ + /dev/mapper/kzak-home on /home/kzak: MOUNTED +-/fooooo on /mnt/foo: MOUNTED + tmpfs on /mnt/test/foo bar: MOUNTED +diff --git a/tests/expected/libmount/tabdiff-move b/tests/expected/libmount/tabdiff-move +index 24f9bc7..95820d9 100644 +--- a/tests/expected/libmount/tabdiff-move ++++ b/tests/expected/libmount/tabdiff-move +@@ -1,3 +1,2 @@ + //foo.home/bar/ on /mnt/music: MOVED to /mnt/music +-/fooooo on /mnt/foo: UMOUNTED + tmpfs on /mnt/test/foo bar: UMOUNTED +diff --git a/tests/expected/libmount/tabdiff-remount b/tests/expected/libmount/tabdiff-remount +index 82ebeab..876bfd9 100644 +--- a/tests/expected/libmount/tabdiff-remount ++++ b/tests/expected/libmount/tabdiff-remount +@@ -1,4 +1,3 @@ + /dev/mapper/kzak-home on /home/kzak: REMOUNTED from 'rw,noatime,barrier=1,data=ordered' to 'ro,noatime,barrier=1,data=ordered' + //foo.home/bar/ on /mnt/sounds: REMOUNTED from 'rw,relatime,unc=\\foo.home\bar,username=kzak,domain=SRGROUP,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.111.1,posixpaths,serverino,acl,rsize=16384,wsize=57344' to 'ro,relatime,unc=\\foo.home\bar,username=kzak,domain=SRGROUP,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.111.1,posixpaths,serverino,acl,rsize=16384,wsize=57344' +-/fooooo on /mnt/foo: UMOUNTED + tmpfs on /mnt/test/foo bar: UMOUNTED +diff --git a/tests/expected/libmount/tabdiff-umount b/tests/expected/libmount/tabdiff-umount +index a3e0fe4..c7be725 100644 +--- a/tests/expected/libmount/tabdiff-umount ++++ b/tests/expected/libmount/tabdiff-umount +@@ -1,3 +1,2 @@ + /dev/mapper/kzak-home on /home/kzak: UMOUNTED +-/fooooo on /mnt/foo: UMOUNTED + tmpfs on /mnt/test/foo bar: UMOUNTED +diff --git a/tests/expected/libmount/tabfiles-parse-mountinfo b/tests/expected/libmount/tabfiles-parse-mountinfo +index 47eb770..d5ba524 100644 +--- a/tests/expected/libmount/tabfiles-parse-mountinfo ++++ b/tests/expected/libmount/tabfiles-parse-mountinfo +@@ -351,17 +351,6 @@ id: 47 + parent: 20 + devno: 0:38 + ------ fs: +-source: /fooooo +-target: /mnt/foo +-fstype: bar +-optstr: rw,relatime +-VFS-optstr: rw,relatime +-FS-opstr: rw +-root: / +-id: 48 +-parent: 20 +-devno: 0:39 +------- fs: + source: tmpfs + target: /mnt/test/foo bar + fstype: tmpfs +diff --git a/tests/expected/libmount/tabfiles-py-parse-mountinfo b/tests/expected/libmount/tabfiles-py-parse-mountinfo +index 47eb770..d5ba524 100644 +--- a/tests/expected/libmount/tabfiles-py-parse-mountinfo ++++ b/tests/expected/libmount/tabfiles-py-parse-mountinfo +@@ -351,17 +351,6 @@ id: 47 + parent: 20 + devno: 0:38 + ------ fs: +-source: /fooooo +-target: /mnt/foo +-fstype: bar +-optstr: rw,relatime +-VFS-optstr: rw,relatime +-FS-opstr: rw +-root: / +-id: 48 +-parent: 20 +-devno: 0:39 +------- fs: + source: tmpfs + target: /mnt/test/foo bar + fstype: tmpfs +diff --git a/tests/ts/findmnt/files/mountinfo b/tests/ts/findmnt/files/mountinfo +index 475ea1a..ff1e664 100644 +--- a/tests/ts/findmnt/files/mountinfo ++++ b/tests/ts/findmnt/files/mountinfo +@@ -30,4 +30,3 @@ + 44 41 0:36 / /home/kzak/.gvfs rw,nosuid,nodev,relatime - fuse.gvfs-fuse-daemon gvfs-fuse-daemon rw,user_id=500,group_id=500 + 45 20 0:37 / /var/lib/nfs/rpc_pipefs rw,relatime - rpc_pipefs sunrpc rw + 47 20 0:38 / /mnt/sounds rw,relatime - cifs //foo.home/bar/ rw,unc=\\foo.home\bar,username=kzak,domain=SRGROUP,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.111.1,posixpaths,serverino,acl,rsize=16384,wsize=57344 +-48 20 0:39 / /mnt/foo\040(deleted) rw,relatime - bar /fooooo rw +diff --git a/tests/ts/findmnt/files/mountinfo-nonroot b/tests/ts/findmnt/files/mountinfo-nonroot +index e15b467..87b421d 100644 +--- a/tests/ts/findmnt/files/mountinfo-nonroot ++++ b/tests/ts/findmnt/files/mountinfo-nonroot +@@ -29,4 +29,3 @@ + 44 41 0:36 / /home/kzak/.gvfs rw,nosuid,nodev,relatime - fuse.gvfs-fuse-daemon gvfs-fuse-daemon rw,user_id=500,group_id=500 + 45 20 0:37 / /var/lib/nfs/rpc_pipefs rw,relatime - rpc_pipefs sunrpc rw + 47 20 0:38 / /mnt/sounds rw,relatime - cifs //foo.home/bar/ rw,unc=\\foo.home\bar,username=kzak,domain=SRGROUP,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.111.1,posixpaths,serverino,acl,rsize=16384,wsize=57344 +-48 20 0:39 / /mnt/foo\040(deleted) rw,relatime - bar /fooooo rw +diff --git a/tests/ts/libmount/files/mountinfo b/tests/ts/libmount/files/mountinfo +index c063071..2b01740 100644 +--- a/tests/ts/libmount/files/mountinfo ++++ b/tests/ts/libmount/files/mountinfo +@@ -30,5 +30,4 @@ + 44 41 0:36 / /home/kzak/.gvfs rw,nosuid,nodev,relatime - fuse.gvfs-fuse-daemon gvfs-fuse-daemon rw,user_id=500,group_id=500 + 45 20 0:37 / /var/lib/nfs/rpc_pipefs rw,relatime - rpc_pipefs sunrpc rw + 47 20 0:38 / /mnt/sounds rw,relatime - cifs //foo.home/bar/ rw,unc=\\foo.home\bar,username=kzak,domain=SRGROUP,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.111.1,posixpaths,serverino,acl,rsize=16384,wsize=57344 +-48 20 0:39 / /mnt/foo\040(deleted) rw,relatime - bar /fooooo rw + 49 20 0:56 / /mnt/test/foo bar rw,relatime shared:323 - tmpfs tmpfs rw +-- +2.27.0 + diff --git a/backport-add-ul_strtou64.patch b/backport-add-ul_strtou64.patch new file mode 100644 index 0000000000000000000000000000000000000000..0b7a56800765b3c3fb33158c3530254b86f37694 --- /dev/null +++ b/backport-add-ul_strtou64.patch @@ -0,0 +1,58 @@ +From a9768580a49403a6ed4fcbc0403936073e301cdb Mon Sep 17 00:00:00 2001 +From: Karel Zak +Date: Tue, 22 Jun 2021 14:20:42 +0200 +Subject: [PATCH] include/strutils: cleanup strto..() functions + +* add ul_strtos64() and ul_strtou64() +* add simple test + +Addresses: https://github.com/karelzak/util-linux/issues/1358 +Signed-off-by: Karel Zak +Reference:https://github.com/util-linux/util-linux/commit/a9768580a49403a6ed4fcbc0403936073e301cdb +Conflict:add ul_strtou64 +--- + include/strutils.h | 2 ++ + lib/strutils.c | 14 ++++++++++++++ + 2 files changed, 16 insertions(+) + +diff --git a/include/strutils.h b/include/strutils.h +index 4b3182f..65b2934 100644 +--- a/include/strutils.h ++++ b/include/strutils.h +@@ -16,6 +16,8 @@ extern int parse_size(const char *str, uintmax_t *res, int *power); + extern int strtosize(const char *str, uintmax_t *res); + extern uintmax_t strtosize_or_err(const char *str, const char *errmesg); + ++extern int ul_strtou64(const char *str, uint64_t *num, int base); ++ + extern int16_t strtos16_or_err(const char *str, const char *errmesg); + extern uint16_t strtou16_or_err(const char *str, const char *errmesg); + extern uint16_t strtox16_or_err(const char *str, const char *errmesg); +diff --git a/lib/strutils.c b/lib/strutils.c +index 6c33820..7befec1 100644 +--- a/lib/strutils.c ++++ b/lib/strutils.c +@@ -320,6 +320,20 @@ char *strndup(const char *s, size_t n) + static uint32_t _strtou32_or_err(const char *str, const char *errmesg, int base); + static uint64_t _strtou64_or_err(const char *str, const char *errmesg, int base); + ++int ul_strtou64(const char *str, uint64_t *num, int base) ++{ ++ char *end = NULL; ++ ++ errno = 0; ++ if (str == NULL || *str == '\0') ++ return -EINVAL; ++ *num = (uint64_t) strtoumax(str, &end, base); ++ ++ if (errno || str == end || (end && *end)) ++ return -EINVAL; ++ return 0; ++} ++ + int16_t strtos16_or_err(const char *str, const char *errmesg) + { + int32_t num = strtos32_or_err(str, errmesg); +-- +2.27.0 + diff --git a/backport-clang-tidy-fix-wrong-cmp-usage.patch b/backport-clang-tidy-fix-wrong-cmp-usage.patch new file mode 100644 index 0000000000000000000000000000000000000000..044e7fd384c15a75f778cccc6eb250ab49a68ae1 --- /dev/null +++ b/backport-clang-tidy-fix-wrong-cmp-usage.patch @@ -0,0 +1,626 @@ +From ad296391f932764de697dd0bfcfa6f529b69a6cb Mon Sep 17 00:00:00 2001 +From: Rosen Penev +Date: Sat, 18 Apr 2020 22:32:29 -0700 +Subject: [PATCH] [clang-tidy] fix wrong *cmp usage + +Found with bugprone-suspicious-string-compare + +Signed-off-by: Rosen Penev +--- + disk-utils/fsck.c | 10 +++++----- + disk-utils/fsck.minix.c | 8 ++++---- + disk-utils/partx.c | 2 +- + lib/ismounted.c | 2 +- + lib/loopdev.c | 2 +- + lib/swapprober.c | 2 +- + lib/sysfs.c | 2 +- + libblkid/src/devname.c | 14 +++++++------- + libblkid/src/partitions/atari.c | 2 +- + libblkid/src/superblocks/ntfs.c | 4 ++-- + libblkid/src/superblocks/vfat.c | 2 +- + libblkid/src/tag.c | 2 +- + libfdisk/src/sgi.c | 2 +- + libmount/src/context.c | 2 +- + libmount/src/context_umount.c | 2 +- + libmount/src/optmap.c | 2 +- + libmount/src/optstr.c | 2 +- + libmount/src/tab_diff.c | 2 +- + libmount/src/tab_parse.c | 2 +- + login-utils/login.c | 2 +- + login-utils/su-common.c | 2 +- + misc-utils/findmnt.c | 2 +- + misc-utils/hardlink.c | 2 +- + misc-utils/lsblk-properties.c | 2 +- + sys-utils/chmem.c | 6 +++--- + sys-utils/lscpu-arm.c | 2 +- + sys-utils/lscpu.c | 4 ++-- + sys-utils/lsmem.c | 4 ++-- + sys-utils/setarch.c | 10 +++++----- + term-utils/agetty.c | 4 ++-- + term-utils/write.c | 2 +- + tests/helpers/test_strerror.c | 2 +- + text-utils/hexdump-display.c | 2 +- + 33 files changed, 56 insertions(+), 56 deletions(-) + +diff --git a/disk-utils/fsck.c b/disk-utils/fsck.c +index 8391e5d..fda80a6 100644 +--- a/disk-utils/fsck.c ++++ b/disk-utils/fsck.c +@@ -819,10 +819,10 @@ static struct fsck_instance *wait_one(int flags) + for (inst2 = instance_list; inst2; inst2 = inst2->next) { + if (inst2->flags & FLAG_DONE) + continue; +- if (strcmp(inst2->type, "ext2") && ++ if (strcmp(inst2->type, "ext2") != 0 && + strcmp(inst2->type, "ext3") && +- strcmp(inst2->type, "ext4") && +- strcmp(inst2->type, "ext4dev")) ++ strcmp(inst2->type, "ext4") != 0 && ++ strcmp(inst2->type, "ext4dev") != 0) + continue; + /* + * If we've just started the fsck, wait a tiny +@@ -903,8 +903,8 @@ static int fsck_device(struct libmnt_fs *fs, int interactive) + + if (type && strcmp(type, "auto") != 0) + ; +- else if (fstype && strncmp(fstype, "no", 2) && +- strncmp(fstype, "opts=", 5) && strncmp(fstype, "loop", 4) && ++ else if (fstype && strncmp(fstype, "no", 2) != 0 && ++ strncmp(fstype, "opts=", 5) != 0 && strncmp(fstype, "loop", 4) != 0 && + !strchr(fstype, ',')) + type = fstype; + else +diff --git a/disk-utils/fsck.minix.c b/disk-utils/fsck.minix.c +index d3725ee..bd44f5b 100644 +--- a/disk-utils/fsck.minix.c ++++ b/disk-utils/fsck.minix.c +@@ -976,7 +976,7 @@ check_file(struct minix_inode *dir, unsigned int offset) { + inode = get_inode(ino); + name_depth--; + if (!offset) { +- if (!inode || strcmp(".", name)) { ++ if (!inode || strcmp(".", name) != 0) { + get_current_name(); + printf(_("%s: bad directory: '.' isn't first\n"), + current_name); +@@ -985,7 +985,7 @@ check_file(struct minix_inode *dir, unsigned int offset) { + return; + } + if (offset == dirsize) { +- if (!inode || strcmp("..", name)) { ++ if (!inode || strcmp("..", name) != 0) { + get_current_name(); + printf(_("%s: bad directory: '..' isn't second\n"), + current_name); +@@ -1049,7 +1049,7 @@ check_file2(struct minix2_inode *dir, unsigned int offset) { + inode = get_inode2(ino); + name_depth--; + if (!offset) { +- if (!inode || strcmp(".", name)) { ++ if (!inode || strcmp(".", name) != 0) { + get_current_name(); + printf(_("%s: bad directory: '.' isn't first\n"), + current_name); +@@ -1058,7 +1058,7 @@ check_file2(struct minix2_inode *dir, unsigned int offset) { + return; + } + if (offset == dirsize) { +- if (!inode || strcmp("..", name)) { ++ if (!inode || strcmp("..", name) != 0) { + get_current_name(); + printf(_("%s: bad directory: '..' isn't second\n"), + current_name); +diff --git a/disk-utils/partx.c b/disk-utils/partx.c +index 4f73c5f..07b3e28 100644 +--- a/disk-utils/partx.c ++++ b/disk-utils/partx.c +@@ -245,7 +245,7 @@ static int get_max_partno(const char *disk, dev_t devno) + if (d->d_type != DT_DIR && d->d_type != DT_UNKNOWN) + continue; + #endif +- if (strncmp(parent, d->d_name, strlen(parent))) ++ if (strncmp(parent, d->d_name, strlen(parent)) != 0) + continue; + snprintf(path, sizeof(path), "%s/partition", d->d_name); + +diff --git a/lib/ismounted.c b/lib/ismounted.c +index fe4c329..9a20b23 100644 +--- a/lib/ismounted.c ++++ b/lib/ismounted.c +@@ -272,7 +272,7 @@ static int is_swap_device(const char *file) + /* Skip the first line */ + if (!fgets(buf, sizeof(buf), f)) + goto leave; +- if (*buf && strncmp(buf, "Filename\t", 9)) ++ if (*buf && strncmp(buf, "Filename\t", 9) != 0) + /* Linux <=2.6.19 contained a bug in the /proc/swaps + * code where the header would not be displayed + */ +diff --git a/lib/loopdev.c b/lib/loopdev.c +index 76eac7b..70cc0c2 100644 +--- a/lib/loopdev.c ++++ b/lib/loopdev.c +@@ -1806,7 +1806,7 @@ int loopdev_count_by_backing_file(const char *filename, char **loopdev) + while(loopcxt_next(&lc) == 0) { + char *backing = loopcxt_get_backing_file(&lc); + +- if (!backing || strcmp(backing, filename)) { ++ if (!backing || strcmp(backing, filename) != 0) { + free(backing); + continue; + } +diff --git a/lib/swapprober.c b/lib/swapprober.c +index 5a4b112..aaf9ad0 100644 +--- a/lib/swapprober.c ++++ b/lib/swapprober.c +@@ -37,7 +37,7 @@ blkid_probe get_swap_prober(const char *devname) + /* Only the SWAPSPACE2 is supported. */ + if (blkid_probe_lookup_value(pr, "VERSION", &version, NULL) == 0 + && version +- && strcmp(version, stringify_value(SWAP_VERSION))) ++ && strcmp(version, stringify_value(SWAP_VERSION)) != 0) + warnx(_("%s: unsupported swap version '%s'"), + devname, version); + else +diff --git a/lib/sysfs.c b/lib/sysfs.c +index ce94400..227a1e9 100644 +--- a/lib/sysfs.c ++++ b/lib/sysfs.c +@@ -869,7 +869,7 @@ dev_t __sysfs_devname_to_devno(const char *prefix, const char *name, const char + goto done; + sysfs_devname_dev_to_sys(_name); + +- if (parent && strncmp("dm-", name, 3)) { ++ if (parent && strncmp("dm-", name, 3) != 0) { + /* + * Create path to /sys/block///dev + */ +diff --git a/libblkid/src/devname.c b/libblkid/src/devname.c +index 3a0f8ab..c58b784 100644 +--- a/libblkid/src/devname.c ++++ b/libblkid/src/devname.c +@@ -58,7 +58,7 @@ blkid_dev blkid_get_dev(blkid_cache cache, const char *devname, int flags) + /* search by name */ + list_for_each(p, &cache->bic_devs) { + tmp = list_entry(p, struct blkid_struct_dev, bid_devs); +- if (strcmp(tmp->bid_name, devname)) ++ if (strcmp(tmp->bid_name, devname) != 0) + continue; + dev = tmp; + break; +@@ -70,7 +70,7 @@ blkid_dev blkid_get_dev(blkid_cache cache, const char *devname, int flags) + DBG(DEVNAME, ul_debug("search canonical %s", cn)); + list_for_each(p, &cache->bic_devs) { + tmp = list_entry(p, struct blkid_struct_dev, bid_devs); +- if (strcmp(tmp->bid_name, cn)) ++ if (strcmp(tmp->bid_name, cn) != 0) + continue; + dev = tmp; + +@@ -120,13 +120,13 @@ blkid_dev blkid_get_dev(blkid_cache cache, const char *devname, int flags) + if (dev2->bid_flags & BLKID_BID_FL_VERIFIED) + continue; + if (!dev->bid_type || !dev2->bid_type || +- strcmp(dev->bid_type, dev2->bid_type)) ++ strcmp(dev->bid_type, dev2->bid_type) != 0) + continue; + if (dev->bid_label && dev2->bid_label && +- strcmp(dev->bid_label, dev2->bid_label)) ++ strcmp(dev->bid_label, dev2->bid_label) != 0) + continue; + if (dev->bid_uuid && dev2->bid_uuid && +- strcmp(dev->bid_uuid, dev2->bid_uuid)) ++ strcmp(dev->bid_uuid, dev2->bid_uuid) != 0) + continue; + if ((dev->bid_label && !dev2->bid_label) || + (!dev->bid_label && dev2->bid_label) || +@@ -160,7 +160,7 @@ static int is_dm_leaf(const char *devname) + while ((de = readdir(dir)) != NULL) { + if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..") || + !strcmp(de->d_name, devname) || +- strncmp(de->d_name, "dm-", 3) || ++ strncmp(de->d_name, "dm-", 3) != 0 || + strlen(de->d_name) > sizeof(path)-32) + continue; + sprintf(path, "/sys/block/%s/slaves", de->d_name); +@@ -544,7 +544,7 @@ static int probe_all(blkid_cache cache, int only_if_new) + * dev, and the device's base name has changed, + * check last as well. + */ +- if (lens[last] && strncmp(ptnames[last], ptname, lens[last])) { ++ if (lens[last] && strncmp(ptnames[last], ptname, lens[last]) != 0) { + DBG(DEVNAME, ul_debug(" whole dev %s, devno 0x%04X", + ptnames[last], (unsigned int) devs[last])); + probe_one(cache, ptnames[last], devs[last], 0, +diff --git a/libblkid/src/partitions/atari.c b/libblkid/src/partitions/atari.c +index 48c3226..f8b6fb5 100644 +--- a/libblkid/src/partitions/atari.c ++++ b/libblkid/src/partitions/atari.c +@@ -164,7 +164,7 @@ static int parse_extended(blkid_probe pr, blkid_partlist ls, + if (!IS_ACTIVE(xrs->part[i+1])) + break; + +- if (memcmp(xrs->part[i+1].id, "XGM", 3)) ++ if (memcmp(xrs->part[i+1].id, "XGM", 3) != 0) + return 0; + + xstart = x0start + be32_to_cpu(xrs->part[i+1].start); +diff --git a/libblkid/src/superblocks/ntfs.c b/libblkid/src/superblocks/ntfs.c +index 02487e2..be2e3d8 100644 +--- a/libblkid/src/superblocks/ntfs.c ++++ b/libblkid/src/superblocks/ntfs.c +@@ -162,7 +162,7 @@ static int __probe_ntfs(blkid_probe pr, const struct blkid_idmag *mag, int save_ + if (!buf_mft) + return errno ? -errno : 1; + +- if (memcmp(buf_mft, "FILE", 4)) ++ if (memcmp(buf_mft, "FILE", 4) != 0) + return 1; + + off += MFT_RECORD_VOLUME * mft_record_size; +@@ -171,7 +171,7 @@ static int __probe_ntfs(blkid_probe pr, const struct blkid_idmag *mag, int save_ + if (!buf_mft) + return errno ? -errno : 1; + +- if (memcmp(buf_mft, "FILE", 4)) ++ if (memcmp(buf_mft, "FILE", 4) != 0) + return 1; + + /* return if caller does not care about UUID and LABEL */ +diff --git a/libblkid/src/superblocks/vfat.c b/libblkid/src/superblocks/vfat.c +index 7c01ceb..c7a3d08 100644 +--- a/libblkid/src/superblocks/vfat.c ++++ b/libblkid/src/superblocks/vfat.c +@@ -425,7 +425,7 @@ static int probe_vfat(blkid_probe pr, const struct blkid_idmag *mag) + } + } + +- if (boot_label && memcmp(boot_label, no_name, 11)) ++ if (boot_label && memcmp(boot_label, no_name, 11) != 0) + blkid_probe_set_id_label(pr, "LABEL_FATBOOT", boot_label, 11); + + if (vol_label) +diff --git a/libblkid/src/tag.c b/libblkid/src/tag.c +index f6b67f6..390a648 100644 +--- a/libblkid/src/tag.c ++++ b/libblkid/src/tag.c +@@ -73,7 +73,7 @@ int blkid_dev_has_tag(blkid_dev dev, const char *type, + tag = blkid_find_tag_dev(dev, type); + if (!value) + return (tag != NULL); +- if (!tag || strcmp(tag->bit_val, value)) ++ if (!tag || strcmp(tag->bit_val, value) != 0) + return 0; + return 1; + } +diff --git a/libfdisk/src/sgi.c b/libfdisk/src/sgi.c +index d5391b5..6b4b5d1 100644 +--- a/libfdisk/src/sgi.c ++++ b/libfdisk/src/sgi.c +@@ -413,7 +413,7 @@ static int sgi_check_bootfile(struct fdisk_context *cxt, const char *name) + } + + if (strncmp(name, (char *) sgilabel->boot_file, +- sizeof(sgilabel->boot_file))) { ++ sizeof(sgilabel->boot_file)) != 0) { + fdisk_warnx(cxt, _("Be aware that the bootfile is not checked " + "for existence. SGI's default is \"/unix\", " + "and for backup \"/unix.save\".")); +diff --git a/libmount/src/context.c b/libmount/src/context.c +index 2b598db..8b548b2 100644 +--- a/libmount/src/context.c ++++ b/libmount/src/context.c +@@ -1808,7 +1808,7 @@ int mnt_context_prepare_srcpath(struct libmnt_context *cxt) + * Source is PATH (canonicalize) + */ + path = mnt_resolve_path(src, cache); +- if (path && strcmp(path, src)) ++ if (path && strcmp(path, src) != 0) + rc = mnt_fs_set_source(cxt->fs, path); + } + +diff --git a/libmount/src/context_umount.c b/libmount/src/context_umount.c +index f3e0799..e1cf7c6 100644 +--- a/libmount/src/context_umount.c ++++ b/libmount/src/context_umount.c +@@ -388,7 +388,7 @@ static int is_associated_fs(const char *devname, struct libmnt_fs *fs) + int flags = 0; + + /* check if it begins with /dev/loop */ +- if (strncmp(devname, _PATH_DEV_LOOP, sizeof(_PATH_DEV_LOOP) - 1)) ++ if (strncmp(devname, _PATH_DEV_LOOP, sizeof(_PATH_DEV_LOOP) - 1) != 0) + return 0; + + src = mnt_fs_get_srcpath(fs); +diff --git a/libmount/src/optmap.c b/libmount/src/optmap.c +index 1f3ace3..a080d8d 100644 +--- a/libmount/src/optmap.c ++++ b/libmount/src/optmap.c +@@ -249,7 +249,7 @@ const struct libmnt_optmap *mnt_optmap_get_entry( + } + continue; + } +- if (strncmp(ent->name, name, namelen)) ++ if (strncmp(ent->name, name, namelen) != 0) + continue; + p = ent->name + namelen; + if (*p == '\0' || *p == '=' || *p == '[') { +diff --git a/libmount/src/optstr.c b/libmount/src/optstr.c +index f975cef..781bb29 100644 +--- a/libmount/src/optstr.c ++++ b/libmount/src/optstr.c +@@ -1077,7 +1077,7 @@ int mnt_optstr_fix_user(char **optstr) + if (!username) + return -ENOMEM; + +- if (!ol.valsz || (ol.value && strncmp(ol.value, username, ol.valsz))) { ++ if (!ol.valsz || (ol.value && strncmp(ol.value, username, ol.valsz) != 0)) { + if (ol.valsz) + /* remove old value */ + mnt_optstr_remove_option_at(optstr, ol.value, ol.end); +diff --git a/libmount/src/tab_diff.c b/libmount/src/tab_diff.c +index fdb1ef5..81694bc 100644 +--- a/libmount/src/tab_diff.c ++++ b/libmount/src/tab_diff.c +@@ -277,7 +277,7 @@ int mnt_diff_tables(struct libmnt_tabdiff *df, struct libmnt_table *old_tab, + *f1 = mnt_fs_get_fs_options(o_fs), + *f2 = mnt_fs_get_fs_options(fs); + +- if ((v1 && v2 && strcmp(v1, v2)) || (f1 && f2 && strcmp(f1, f2))) ++ if ((v1 && v2 && strcmp(v1, v2) != 0) || (f1 && f2 && strcmp(f1, f2) != 0)) + tabdiff_add_entry(df, o_fs, fs, MNT_TABDIFF_REMOUNT); + } + } +diff --git a/libmount/src/tab_parse.c b/libmount/src/tab_parse.c +index ffcf245..3b52f6b 100644 +--- a/libmount/src/tab_parse.c ++++ b/libmount/src/tab_parse.c +@@ -885,7 +885,7 @@ static int mnt_table_parse_dir_filter(const struct dirent *d) + namesz = strlen(d->d_name); + if (!namesz || namesz < MNT_MNTTABDIR_EXTSIZ + 1 || + strcmp(d->d_name + (namesz - MNT_MNTTABDIR_EXTSIZ), +- MNT_MNTTABDIR_EXT)) ++ MNT_MNTTABDIR_EXT) != 0) + return 0; + + /* Accept this */ +diff --git a/login-utils/login.c b/login-utils/login.c +index 457bd98..30940a6 100644 +--- a/login-utils/login.c ++++ b/login-utils/login.c +@@ -377,7 +377,7 @@ static void init_tty(struct login_context *cxt) + */ + if (!cxt->tty_path || !*cxt->tty_path || + lstat(cxt->tty_path, &st) != 0 || !S_ISCHR(st.st_mode) || +- (st.st_nlink > 1 && strncmp(cxt->tty_path, "/dev/", 5)) || ++ (st.st_nlink > 1 && strncmp(cxt->tty_path, "/dev/", 5) != 0) || + access(cxt->tty_path, R_OK | W_OK) != 0) { + + syslog(LOG_ERR, _("FATAL: bad tty")); +diff --git a/login-utils/su-common.c b/login-utils/su-common.c +index e671d82..3cd7f59 100644 +--- a/login-utils/su-common.c ++++ b/login-utils/su-common.c +@@ -1149,7 +1149,7 @@ int su_main(int argc, char **argv, int mode) + shell = getenv("SHELL"); + + if (shell +- && strcmp(shell, su->pwd->pw_shell) ++ && strcmp(shell, su->pwd->pw_shell) != 0 + && getuid() != 0 + && is_restricted_shell(su->pwd->pw_shell)) { + /* The user being su'd to has a nonstandard shell, and +diff --git a/misc-utils/findmnt.c b/misc-utils/findmnt.c +index 53f647f..43b4dc7 100644 +--- a/misc-utils/findmnt.c ++++ b/misc-utils/findmnt.c +@@ -524,7 +524,7 @@ static char *get_data(struct libmnt_fs *fs, int num) + if (spec && (flags & FL_EVALUATE)) + spec = cn = mnt_resolve_spec(spec, cache); + } +- if (root && spec && !(flags & FL_NOFSROOT) && strcmp(root, "/")) ++ if (root && spec && !(flags & FL_NOFSROOT) && strcmp(root, "/") != 0) + xasprintf(&str, "%s[%s]", spec, root); + else if (spec) + str = xstrdup(spec); +diff --git a/misc-utils/hardlink.c b/misc-utils/hardlink.c +index 6361589..e985aaf 100644 +--- a/misc-utils/hardlink.c ++++ b/misc-utils/hardlink.c +@@ -296,7 +296,7 @@ static void process_path(struct hardlink_ctl *ctl, const char *name) + close(fd2); + return; + } +- if (memcmp(ctl->iobuf1, ctl->iobuf2, rsize)) ++ if (memcmp(ctl->iobuf1, ctl->iobuf2, rsize) != 0) + break; + } + close(fd2); +diff --git a/misc-utils/lsblk-properties.c b/misc-utils/lsblk-properties.c +index a1c73bc..6f41eac 100644 +--- a/misc-utils/lsblk-properties.c ++++ b/misc-utils/lsblk-properties.c +@@ -136,7 +136,7 @@ static int lookup(char *buf, char *pattern, char **value) + return 0; + + len = strlen(pattern); +- if (strncmp(buf, pattern, len)) ++ if (strncmp(buf, pattern, len) != 0) + return 0; + + p = buf + len; +diff --git a/sys-utils/chmem.c b/sys-utils/chmem.c +index b3645be..2f231d6 100644 +--- a/sys-utils/chmem.c ++++ b/sys-utils/chmem.c +@@ -133,7 +133,7 @@ static int chmem_size(struct chmem_desc *desc, int enable, int zone_id) + zn = zone_names[zone_id]; + if (enable && !strcasestr(line, zn)) + continue; +- if (!enable && strncasecmp(line, zn, strlen(zn))) ++ if (!enable && strncasecmp(line, zn, strlen(zn)) != 0) + continue; + } else if (enable) { + /* By default, use zone Movable for online, if valid */ +@@ -218,7 +218,7 @@ static int chmem_range(struct chmem_desc *desc, int enable, int zone_id) + warnx(_("%s enable failed: Zone mismatch"), str); + continue; + } +- if (!enable && strncasecmp(line, zn, strlen(zn))) { ++ if (!enable && strncasecmp(line, zn, strlen(zn)) != 0) { + warnx(_("%s disable failed: Zone mismatch"), str); + continue; + } +@@ -251,7 +251,7 @@ static int chmem_range(struct chmem_desc *desc, int enable, int zone_id) + + static int filter(const struct dirent *de) + { +- if (strncmp("memory", de->d_name, 6)) ++ if (strncmp("memory", de->d_name, 6) != 0) + return 0; + return isdigit_string(de->d_name + 6); + } +diff --git a/sys-utils/lscpu-arm.c b/sys-utils/lscpu-arm.c +index ef9d1ff..aa7d826 100644 +--- a/sys-utils/lscpu-arm.c ++++ b/sys-utils/lscpu-arm.c +@@ -209,7 +209,7 @@ void arm_cpu_decode(struct lscpu_desc *desc) + + if (desc->vendor == NULL || desc->model == NULL) + return; +- if ((strncmp(desc->vendor,"0x",2) || strncmp(desc->model,"0x",2) )) ++ if ((strncmp(desc->vendor,"0x",2) != 0 || strncmp(desc->model,"0x",2) )) + return; + + errno = 0; +diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c +index 79b94dc..d6c3f2e 100644 +--- a/sys-utils/lscpu.c ++++ b/sys-utils/lscpu.c +@@ -277,7 +277,7 @@ lookup(char *line, char *pattern, char **value) + return 0; + + /* pattern */ +- if (strncmp(line, pattern, len)) ++ if (strncmp(line, pattern, len) != 0) + return 0; + + /* white spaces */ +@@ -322,7 +322,7 @@ lookup_cache(char *line, struct lscpu_desc *desc) + int level; + + /* Make sure line starts with "cache :" */ +- if (strncmp(line, "cache", 5)) ++ if (strncmp(line, "cache", 5) != 0) + return 0; + for (p = line + 5; isdigit(*p); p++); + for (; isspace(*p); p++); +diff --git a/sys-utils/lsmem.c b/sys-utils/lsmem.c +index a1272ae..45775d9 100644 +--- a/sys-utils/lsmem.c ++++ b/sys-utils/lsmem.c +@@ -344,7 +344,7 @@ static int memory_block_get_node(struct lsmem *lsmem, char *name) + + node = -1; + while ((de = readdir(dir)) != NULL) { +- if (strncmp("node", de->d_name, 4)) ++ if (strncmp("node", de->d_name, 4) != 0) + continue; + if (!isdigit_string(de->d_name + 4)) + continue; +@@ -459,7 +459,7 @@ static void read_info(struct lsmem *lsmem) + + static int memory_block_filter(const struct dirent *de) + { +- if (strncmp("memory", de->d_name, 6)) ++ if (strncmp("memory", de->d_name, 6) != 0) + return 0; + return isdigit_string(de->d_name + 6); + } +diff --git a/sys-utils/setarch.c b/sys-utils/setarch.c +index 1a2ae1b..cb4b081 100644 +--- a/sys-utils/setarch.c ++++ b/sys-utils/setarch.c +@@ -262,12 +262,12 @@ static void verify_arch_domain(struct arch_domain *dom, const char *wanted) + return; + + uname(&un); +- if (strcmp(un.machine, dom->result_arch)) { +- if (strcmp(dom->result_arch, "i386") +- || (strcmp(un.machine, "i486") ++ if (strcmp(un.machine, dom->result_arch) != 0) { ++ if (strcmp(dom->result_arch, "i386") != 0 ++ || (strcmp(un.machine, "i486") != 0 + && strcmp(un.machine, "i586") +- && strcmp(un.machine, "i686") +- && strcmp(un.machine, "athlon"))) ++ && strcmp(un.machine, "i686") != 0 ++ && strcmp(un.machine, "athlon") != 0)) + errx(EXIT_FAILURE, _("Kernel cannot set architecture to %s"), wanted); + } + } +diff --git a/term-utils/agetty.c b/term-utils/agetty.c +index f88a8da..861a56d 100644 +--- a/term-utils/agetty.c ++++ b/term-utils/agetty.c +@@ -580,7 +580,7 @@ static char *replace_u(char *str, char *username) + size_t sz; + char *tp, *old = entry; + +- if (memcmp(p, "\\u", 2)) { ++ if (memcmp(p, "\\u", 2) != 0) { + p++; + continue; /* no \u */ + } +@@ -1732,7 +1732,7 @@ static int issuedir_filter(const struct dirent *d) + + namesz = strlen(d->d_name); + if (!namesz || namesz < ISSUEDIR_EXTSIZ + 1 || +- strcmp(d->d_name + (namesz - ISSUEDIR_EXTSIZ), ISSUEDIR_EXT)) ++ strcmp(d->d_name + (namesz - ISSUEDIR_EXTSIZ), ISSUEDIR_EXT) != 0) + return 0; + + /* Accept this */ +diff --git a/term-utils/write.c b/term-utils/write.c +index 90eb18c..50f18dc 100644 +--- a/term-utils/write.c ++++ b/term-utils/write.c +@@ -275,7 +275,7 @@ static void do_write(const struct write_control *ctl) + tm = localtime(&now); + /* print greeting */ + printf("\r\n\a\a\a"); +- if (strcmp(login, pwuid)) ++ if (strcmp(login, pwuid) != 0) + printf(_("Message from %s@%s (as %s) on %s at %02d:%02d ..."), + login, host, pwuid, ctl->src_tty_name, + tm->tm_hour, tm->tm_min); +diff --git a/tests/helpers/test_strerror.c b/tests/helpers/test_strerror.c +index a063b11..f51f698 100644 +--- a/tests/helpers/test_strerror.c ++++ b/tests/helpers/test_strerror.c +@@ -33,7 +33,7 @@ int main(int argc, const char *argv[]) + } + + for (i = 0; i < sizeof(errors)/sizeof(*errors); i++) { +- if (strcmp(errors[i].str, argv[1])) ++ if (strcmp(errors[i].str, argv[1]) != 0) + continue; + puts(strerror(errors[i].error)); + return 0; +diff --git a/text-utils/hexdump-display.c b/text-utils/hexdump-display.c +index 6399608..695b472 100644 +--- a/text-utils/hexdump-display.c ++++ b/text-utils/hexdump-display.c +@@ -377,7 +377,7 @@ get(struct hexdump *hex) + hex->length -= n; + if (!(need -= n)) { + if (vflag == ALL || vflag == FIRST || +- memcmp(curp, savp, hex->blocksize)) { ++ memcmp(curp, savp, hex->blocksize) != 0) { + if (vflag == DUP || vflag == FIRST) + vflag = WAIT; + return(curp); +-- +1.8.3.1 + diff --git a/backport-fdisk-add-support-for-parttype-aliases.patch b/backport-fdisk-add-support-for-parttype-aliases.patch new file mode 100644 index 0000000000000000000000000000000000000000..5645906cc6493058d9c1ab6d87169db268e74eba --- /dev/null +++ b/backport-fdisk-add-support-for-parttype-aliases.patch @@ -0,0 +1,133 @@ +From 006607abb5c0bc40f1f94da94abb14f0668d8205 Mon Sep 17 00:00:00 2001 +From: Karel Zak +Date: Tue, 3 Mar 2020 16:10:02 +0100 +Subject: [PATCH] fdisk: add support for parttype aliases + +* add list of supported aliases to 'l' and 'L' output +* support aliases in 't' dialog + +For example (use 'swap' to set 0x82 partition type): + + Command (m for help): t + Selected partition 1 + Hex code or alias (type L to list all): swap + Changed type of partition 'Linux' to 'Linux swap / Solaris'. + +Note that the aliases are evaluated as the last possibility if user's +input dues not match up with any partition type. This is necessary for +backward compatibility. + +This patch does NOT introduce shortcuts (.e.g. 'S' for swap) to +fdisk(8) due to collisions with already used dialog keys. + +Addresses: https://github.com/karelzak/util-linux/issues/958 +Signed-off-by: Karel Zak +--- + disk-utils/fdisk.c | 50 +++++++++++++++++++++++++++++++++++++--------- + 1 file changed, 41 insertions(+), 9 deletions(-) + +diff --git a/disk-utils/fdisk.c b/disk-utils/fdisk.c +index a539c70ef..17d60b1a9 100644 +--- a/disk-utils/fdisk.c ++++ b/disk-utils/fdisk.c +@@ -480,9 +480,15 @@ static struct fdisk_parttype *ask_partition_type(struct fdisk_context *cxt, int + return NULL; + + *canceled = 0; +- q = fdisk_label_has_code_parttypes(lb) ? +- _("Hex code (type L to list all codes): ") : +- _("Partition type (type L to list all types): "); ++ ++ if (fdisk_label_has_parttypes_shortcuts(lb)) ++ q = fdisk_label_has_code_parttypes(lb) ? ++ _("Hex code or alias (type L to list all): ") : ++ _("Partition type or alias (type L to list all): "); ++ else ++ q = fdisk_label_has_code_parttypes(lb) ? ++ _("Hex code (type L to list all codes): ") : ++ _("Partition type (type L to list all types): "); + do { + char buf[256] = { '\0' }; + int rc = get_user_reply(q, buf, sizeof(buf)); +@@ -496,8 +502,10 @@ static struct fdisk_parttype *ask_partition_type(struct fdisk_context *cxt, int + if (buf[1] == '\0' && toupper(*buf) == 'L') + list_partition_types(cxt); + else if (*buf) { +- struct fdisk_parttype *t = fdisk_label_parse_parttype(lb, buf); +- ++ struct fdisk_parttype *t = fdisk_label_advparse_parttype(lb, buf, ++ FDISK_PARTTYPE_PARSE_DATA ++ | FDISK_PARTTYPE_PARSE_ALIAS ++ | FDISK_PARTTYPE_PARSE_SEQNUM); + if (!t) + fdisk_info(cxt, _("Failed to parse '%s' partition type."), buf); + return t; +@@ -510,8 +518,9 @@ static struct fdisk_parttype *ask_partition_type(struct fdisk_context *cxt, int + + void list_partition_types(struct fdisk_context *cxt) + { +- size_t ntypes = 0; ++ size_t ntypes = 0, next = 0; + struct fdisk_label *lb; ++ int pager = 0; + + assert(cxt); + lb = fdisk_get_label(cxt, NULL); +@@ -525,7 +534,7 @@ void list_partition_types(struct fdisk_context *cxt) + /* + * Prints in 4 columns in format + */ +- size_t last[4], done = 0, next = 0, size; ++ size_t last[4], done = 0, size; + int i; + + size = ntypes; +@@ -562,6 +571,7 @@ void list_partition_types(struct fdisk_context *cxt) + } + } while (done < last[0]); + ++ putchar('\n'); + } else { + /* + * Prints 1 column in format +@@ -569,6 +579,7 @@ void list_partition_types(struct fdisk_context *cxt) + size_t i; + + pager_open(); ++ pager = 1; + + for (i = 0; i < ntypes; i++) { + const struct fdisk_parttype *t = fdisk_label_get_parttype(lb, i); +@@ -577,9 +588,30 @@ void list_partition_types(struct fdisk_context *cxt) + fdisk_parttype_get_string(t)); + } + +- pager_close(); + } +- putchar('\n'); ++ ++ ++ /* ++ * Aliases ++ */ ++ if (fdisk_label_has_parttypes_shortcuts(lb)) { ++ const char *alias = NULL, *typestr = NULL; ++ int rc = 0; ++ ++ fputs(_("\nAliases:\n"), stdout); ++ ++ for (next = 0; rc == 0 || rc == 2; next++) { ++ /* rc: <0 error, 0 success, 1 end, 2 deprecated */ ++ rc = fdisk_label_get_parttype_shortcut(lb, ++ next, &typestr, NULL, &alias); ++ if (rc == 0) ++ printf(" %-14s - %s\n", alias, typestr); ++ } ++ } ++ ++ if (pager) ++ pager_close(); ++ + } + + void toggle_dos_compatibility_flag(struct fdisk_context *cxt) diff --git a/backport-lib-strutils-fix-floating-point-exception.patch b/backport-lib-strutils-fix-floating-point-exception.patch new file mode 100644 index 0000000000000000000000000000000000000000..cdb8f1b69e946970ac0eade8b1998c8e08b7a41a --- /dev/null +++ b/backport-lib-strutils-fix-floating-point-exception.patch @@ -0,0 +1,24 @@ +From 1186cdf336e9d29089de54ff59dba6d2ee1bd803 Mon Sep 17 00:00:00 2001 +From: Karel Zak +Date: Tue, 28 Apr 2020 12:28:59 +0200 +Subject: [PATCH] lib/strutils: fix floating point exception + +Addresses: https://github.com/karelzak/util-linux/issues/1017 +Signed-off-by: Karel Zak +--- + lib/strutils.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/lib/strutils.c b/lib/strutils.c +index e1629fb56..609ef0860 100644 +--- a/lib/strutils.c ++++ b/lib/strutils.c +@@ -195,7 +195,7 @@ int parse_size(const char *str, uintmax_t *res, int *power) + frac /= 10; /* remove last digit from frac */ + frac_poz *= 10; + +- if (seg) ++ if (seg && seg_div / seg) + x += frac_base / (seg_div / seg); + } while (frac); + } diff --git a/backport-libblkid-improve-debug-for-proc-partitions.patch b/backport-libblkid-improve-debug-for-proc-partitions.patch new file mode 100644 index 0000000000000000000000000000000000000000..718444700b5f36c93c18249aa93be6dab4de4cda --- /dev/null +++ b/backport-libblkid-improve-debug-for-proc-partitions.patch @@ -0,0 +1,75 @@ +From e9131920485962f33bd32b492cb93078ee7a3c34 Mon Sep 17 00:00:00 2001 +From: Karel Zak +Date: Wed, 30 Sep 2020 11:37:09 +0200 +Subject: [PATCH] libblkid: improve debug for /proc/partitions + +Signed-off-by: Karel Zak +--- + libblkid/src/devname.c | 15 +++++++++------ + 1 file changed, 9 insertions(+), 6 deletions(-) + +diff --git a/libblkid/src/devname.c b/libblkid/src/devname.c +index c58b784..8f2d89a 100644 +--- a/libblkid/src/devname.c ++++ b/libblkid/src/devname.c +@@ -351,7 +351,7 @@ static void lvm_probe_all(blkid_cache cache, int only_if_new) + lv_name); + dev = lvm_get_devno(lvm_device); + sprintf(lvm_device, "%s/%s", vg_name, lv_name); +- DBG(DEVNAME, ul_debug("LVM dev %s: devno 0x%04X", ++ DBG(DEVNAME, ul_debug("Probe LVM dev %s: devno 0x%04X", + lvm_device, + (unsigned int) dev)); + probe_one(cache, lvm_device, dev, BLKID_PRI_LVM, +@@ -383,7 +383,7 @@ evms_probe_all(blkid_cache cache, int only_if_new) + &ma, &mi, &sz, device) != 4) + continue; + +- DBG(DEVNAME, ul_debug("Checking partition %s (%d, %d)", ++ DBG(DEVNAME, ul_debug("Probe EVMS partition %s (%d, %d)", + device, ma, mi)); + + probe_one(cache, device, makedev(ma, mi), BLKID_PRI_EVMS, +@@ -433,7 +433,7 @@ ubi_probe_all(blkid_cache cache, int only_if_new) + + if (!S_ISCHR(st.st_mode) || !minor(dev)) + continue; +- DBG(DEVNAME, ul_debug("UBI vol %s/%s: devno 0x%04X", ++ DBG(DEVNAME, ul_debug("Probe UBI vol %s/%s: devno 0x%04X", + *dirname, name, (int) dev)); + probe_one(cache, name, dev, BLKID_PRI_UBI, only_if_new, 0); + } +@@ -506,7 +506,7 @@ static int probe_all(blkid_cache cache, int only_if_new) + + /* probably partition, so check */ + if (!iswhole[which]) { +- DBG(DEVNAME, ul_debug(" partition dev %s, devno 0x%04X", ++ DBG(DEVNAME, ul_debug(" Probe partition dev %s, devno 0x%04X", + ptname, (unsigned int) devs[which])); + + if (sz > 1) +@@ -545,7 +545,7 @@ static int probe_all(blkid_cache cache, int only_if_new) + * check last as well. + */ + if (lens[last] && strncmp(ptnames[last], ptname, lens[last]) != 0) { +- DBG(DEVNAME, ul_debug(" whole dev %s, devno 0x%04X", ++ DBG(DEVNAME, ul_debug(" Probe whole dev %s, devno 0x%04X", + ptnames[last], (unsigned int) devs[last])); + probe_one(cache, ptnames[last], devs[last], 0, + only_if_new, 0); +@@ -555,8 +555,11 @@ static int probe_all(blkid_cache cache, int only_if_new) + } + + /* Handle the last device if it wasn't partitioned */ +- if (lens[which]) ++ if (lens[which]) { ++ DBG(DEVNAME, ul_debug(" Probe whole dev %s, devno 0x%04X", ++ ptname, (unsigned int) devs[which])); + probe_one(cache, ptname, devs[which], 0, only_if_new, 0); ++ } + + fclose(proc); + blkid_flush_cache(cache); +-- +1.8.3.1 + diff --git a/backport-libblkid-use-sys-to-read-all-block-devices.patch b/backport-libblkid-use-sys-to-read-all-block-devices.patch new file mode 100644 index 0000000000000000000000000000000000000000..893fbd98ad3aeed08706bd21c9c45c4194001d40 --- /dev/null +++ b/backport-libblkid-use-sys-to-read-all-block-devices.patch @@ -0,0 +1,416 @@ +From 8d3f9430c59416e4c1eddc899578158a7a1ed414 Mon Sep 17 00:00:00 2001 +From: Karel Zak +Date: Wed, 7 Oct 2020 13:49:45 +0200 +Subject: [PATCH] libblkid: use /sys to read all block devices + +The old implementation uses /proc/partitions where devices are +filtered by kernel (missing devices with ext_range=1 and removable +devices). + +The problem with the old implementation is whole-disk heuristic based +on device name, order of devices, etc. + +The new implementation use the same code to read also removable +devices. + +Addresses: https://github.com/karelzak/util-linux/issues/1151 +Signed-off-by: Karel Zak +--- + lib/sysfs.c | 36 +++++--- + libblkid/src/blkidP.h | 2 +- + libblkid/src/devname.c | 235 +++++++++++++++++++++---------------------------- + 3 files changed, 128 insertions(+), 145 deletions(-) + +diff --git a/lib/sysfs.c b/lib/sysfs.c +index 5b4de2c..0c360ce 100644 +--- a/lib/sysfs.c ++++ b/lib/sysfs.c +@@ -874,7 +874,7 @@ int sysfs_devname_is_hidden(const char *prefix, const char *name) + dev_t __sysfs_devname_to_devno(const char *prefix, const char *name, const char *parent) + { + char buf[PATH_MAX]; +- char *_name = NULL; /* name as encoded in sysfs */ ++ char *_name = NULL, *_parent = NULL; /* name as encoded in sysfs */ + dev_t dev = 0; + int len; + +@@ -901,21 +901,22 @@ dev_t __sysfs_devname_to_devno(const char *prefix, const char *name, const char + goto done; + sysfs_devname_dev_to_sys(_name); + +- if (parent && strncmp("dm-", name, 3) != 0) { +- /* +- * Create path to /sys/block///dev +- */ +- char *_parent = strdup(parent); +- ++ if (parent) { ++ _parent = strdup(parent); + if (!_parent) { + free(_parent); + goto done; + } ++ } ++ ++ if (parent && strncmp("dm-", name, 3) != 0) { ++ /* ++ * Create path to /sys/block///dev ++ */ + sysfs_devname_dev_to_sys(_parent); + len = snprintf(buf, sizeof(buf), + "%s" _PATH_SYS_BLOCK "/%s/%s/dev", + prefix, _parent, _name); +- free(_parent); + if (len < 0 || (size_t) len >= sizeof(buf)) + goto done; + +@@ -934,10 +935,22 @@ dev_t __sysfs_devname_to_devno(const char *prefix, const char *name, const char + goto done; + dev = read_devno(buf); + ++ /* ++ * Read from /sys/block///dev ++ */ ++ if (!dev && parent && startswith(name, parent)) { ++ len = snprintf(buf, sizeof(buf), ++ "%s" _PATH_SYS_BLOCK "/%s/%s/dev", ++ prefix, _parent, _name); ++ if (len < 0 || (size_t) len >= sizeof(buf)) ++ goto done; ++ dev = read_devno(buf); ++ } ++ ++ /* ++ * Read from /sys/block//device/dev ++ */ + if (!dev) { +- /* +- * Read from /sys/block//device/dev +- */ + len = snprintf(buf, sizeof(buf), + "%s" _PATH_SYS_BLOCK "/%s/device/dev", + prefix, _name); +@@ -947,6 +960,7 @@ dev_t __sysfs_devname_to_devno(const char *prefix, const char *name, const char + } + done: + free(_name); ++ free(_parent); + return dev; + } + +diff --git a/libblkid/src/blkidP.h b/libblkid/src/blkidP.h +index 802a1b3..fe3736f 100644 +--- a/libblkid/src/blkidP.h ++++ b/libblkid/src/blkidP.h +@@ -301,7 +301,7 @@ struct blkid_struct_cache + #define BLKID_PROBE_NONE 1 + + #define BLKID_ERR_IO 5 +-#define BLKID_ERR_PROC 9 ++#define BLKID_ERR_SYSFS 9 + #define BLKID_ERR_MEM 12 + #define BLKID_ERR_CACHE 14 + #define BLKID_ERR_DEV 19 +diff --git a/libblkid/src/devname.c b/libblkid/src/devname.c +index 8f2d89a..4b9df5a 100644 +--- a/libblkid/src/devname.c ++++ b/libblkid/src/devname.c +@@ -39,6 +39,7 @@ + #include "canonicalize.h" /* $(top_srcdir)/include */ + #include "pathnames.h" + #include "sysfs.h" ++#include "fileutils.h" + + /* + * Find a dev struct in the cache by device name, if available. +@@ -442,178 +443,146 @@ ubi_probe_all(blkid_cache cache, int only_if_new) + } + + /* +- * Read the device data for all available block devices in the system. ++ * This function uses /sys to read all block devices in way compatible with ++ * /proc/partitions (like the original libblkid implementation) + */ +-static int probe_all(blkid_cache cache, int only_if_new) ++static int ++sysfs_probe_all(blkid_cache cache, int only_if_new, int only_removable) + { +- FILE *proc; +- char line[1024]; +- char ptname0[128 + 1], ptname1[128 + 1], *ptname = NULL; +- char *ptnames[2]; +- dev_t devs[2] = { 0, 0 }; +- int iswhole[2] = { 0, 0 }; +- int ma, mi; +- unsigned long long sz; +- int lens[2] = { 0, 0 }; +- int which = 0, last = 0; +- struct list_head *p, *pnext; ++ DIR *sysfs; ++ struct dirent *dev; + +- ptnames[0] = ptname0; +- ptnames[1] = ptname1; ++ sysfs = opendir(_PATH_SYS_BLOCK); ++ if (!sysfs) ++ return -BLKID_ERR_SYSFS; + +- if (!cache) +- return -BLKID_ERR_PARAM; ++ /* scan /sys/block */ ++ while ((dev = xreaddir(sysfs))) { ++ DIR *dir = NULL; ++ dev_t devno; ++ size_t nparts = 0; ++ unsigned int maxparts = 0, removable = 0; ++ struct dirent *part; ++ struct path_cxt *pc = NULL; ++ uint64_t size = 0; + +- if (cache->bic_flags & BLKID_BIC_FL_PROBED && +- time(NULL) - cache->bic_time < BLKID_PROBE_INTERVAL) +- return 0; ++ DBG(DEVNAME, ul_debug("checking %s", dev->d_name)); + +- blkid_read_cache(cache); +- evms_probe_all(cache, only_if_new); +-#ifdef VG_DIR +- lvm_probe_all(cache, only_if_new); +-#endif +- ubi_probe_all(cache, only_if_new); ++ devno = sysfs_devname_to_devno(dev->d_name); ++ if (!devno) ++ goto next; ++ pc = ul_new_sysfs_path(devno, NULL, NULL); ++ if (!pc) ++ goto next; ++ ++ if (ul_path_read_u64(pc, &size, "size") != 0) ++ size = 0; ++ if (ul_path_read_u32(pc, &removable, "removable") != 0) ++ removable = 0; ++ ++ /* ingnore empty devices */ ++ if (!size) ++ goto next; ++ ++ /* accept removeable if only removable requested */ ++ if (only_removable) { ++ if (!removable) ++ goto next; ++ ++ /* emulate /proc/partitions ++ * -- ignore empty devices and non-partitionable removable devices */ ++ } else { ++ if (ul_path_read_u32(pc, &maxparts, "ext_range") != 0) ++ maxparts = 0; ++ if (!maxparts && removable) ++ goto next; ++ } + +- proc = fopen(PROC_PARTITIONS, "r" UL_CLOEXECSTR); +- if (!proc) +- return -BLKID_ERR_PROC; ++ DBG(DEVNAME, ul_debug("read device name %s", dev->d_name)); + +- while (fgets(line, sizeof(line), proc)) { +- last = which; +- which ^= 1; +- ptname = ptnames[which]; ++ dir = ul_path_opendir(pc, NULL); ++ if (!dir) ++ goto next; + +- if (sscanf(line, " %d %d %llu %128[^\n ]", +- &ma, &mi, &sz, ptname) != 4) +- continue; +- devs[which] = makedev(ma, mi); +- +- DBG(DEVNAME, ul_debug("read device name %s", ptname)); +- +- /* Skip whole disk devs unless they have no partitions. +- * If base name of device has changed, also +- * check previous dev to see if it didn't have a partn. +- * heuristic: partition name ends in a digit, & partition +- * names contain whole device name as substring. +- * +- * Skip extended partitions. +- * heuristic: size is 1 +- */ ++ /* read /sys/block// do get partitions */ ++ while ((part = xreaddir(dir))) { ++ dev_t partno; + +- lens[which] = strlen(ptname); +- iswhole[which] = sysfs_devno_is_wholedisk(devs[which]); ++ if (!sysfs_blkdev_is_partition_dirent(dir, part, dev->d_name)) ++ continue; + +- /* probably partition, so check */ +- if (!iswhole[which]) { +- DBG(DEVNAME, ul_debug(" Probe partition dev %s, devno 0x%04X", +- ptname, (unsigned int) devs[which])); ++ /* ignore extended partitions ++ * -- recount size to blocks like /proc/partitions */ ++ if (ul_path_readf_u64(pc, &size, "%s/size", part->d_name) == 0 ++ && (size >> 1) == 1) ++ continue; ++ partno = __sysfs_devname_to_devno(NULL, part->d_name, dev->d_name); ++ if (!partno) ++ continue; + +- if (sz > 1) +- probe_one(cache, ptname, devs[which], 0, +- only_if_new, 0); +- lens[which] = 0; /* mark as checked */ ++ DBG(DEVNAME, ul_debug(" Probe partition dev %s, devno 0x%04X", ++ part->d_name, (unsigned int) partno)); ++ nparts++; ++ probe_one(cache, part->d_name, partno, 0, only_if_new, 0); + } + +- /* +- * If last was a whole disk and we just found a partition +- * on it, remove the whole-disk dev from the cache if +- * it exists. +- */ +- if (lens[last] && iswhole[last] +- && !strncmp(ptnames[last], ptname, lens[last])) { ++ if (!nparts) { ++ /* add non-partitioned whole disk to cache */ ++ DBG(DEVNAME, ul_debug(" Probe whole dev %s, devno 0x%04X", ++ dev->d_name, (unsigned int) devno)); ++ probe_one(cache, dev->d_name, devno, 0, only_if_new, 0); ++ } else { ++ /* remove partitioned whole-disk from cache */ ++ struct list_head *p, *pnext; + + list_for_each_safe(p, pnext, &cache->bic_devs) { +- blkid_dev tmp; +- +- /* find blkid dev for the whole-disk devno */ +- tmp = list_entry(p, struct blkid_struct_dev, +- bid_devs); +- if (tmp->bid_devno == devs[last]) { +- DBG(DEVNAME, ul_debug(" freeing %s", +- tmp->bid_name)); ++ blkid_dev tmp = list_entry(p, struct blkid_struct_dev, ++ bid_devs); ++ if (tmp->bid_devno == devno) { ++ DBG(DEVNAME, ul_debug(" freeing %s", tmp->bid_name)); + blkid_free_dev(tmp); + cache->bic_flags |= BLKID_BIC_FL_CHANGED; + break; + } + } +- lens[last] = 0; /* mark as checked */ +- } +- /* +- * If last was not checked because it looked like a whole-disk +- * dev, and the device's base name has changed, +- * check last as well. +- */ +- if (lens[last] && strncmp(ptnames[last], ptname, lens[last]) != 0) { +- DBG(DEVNAME, ul_debug(" Probe whole dev %s, devno 0x%04X", +- ptnames[last], (unsigned int) devs[last])); +- probe_one(cache, ptnames[last], devs[last], 0, +- only_if_new, 0); +- +- lens[last] = 0; /* mark as checked */ + } ++ next: ++ if (dir) ++ closedir(dir); ++ if (pc) ++ ul_unref_path(pc); + } + +- /* Handle the last device if it wasn't partitioned */ +- if (lens[which]) { +- DBG(DEVNAME, ul_debug(" Probe whole dev %s, devno 0x%04X", +- ptname, (unsigned int) devs[which])); +- probe_one(cache, ptname, devs[which], 0, only_if_new, 0); +- } +- +- fclose(proc); +- blkid_flush_cache(cache); ++ closedir(sysfs); + return 0; + } + +-/* Don't use it by default -- it's pretty slow (because cdroms, floppy, ...) ++/* ++ * Read the device data for all available block devices in the system. + */ +-static int probe_all_removable(blkid_cache cache) ++static int probe_all(blkid_cache cache, int only_if_new) + { +- struct path_cxt *pc; +- DIR *dir; +- struct dirent *d; +- + if (!cache) + return -BLKID_ERR_PARAM; + +- dir = opendir(_PATH_SYS_BLOCK); +- if (!dir) +- return -BLKID_ERR_PROC; +- +- pc = ul_new_path(NULL); ++ if (cache->bic_flags & BLKID_BIC_FL_PROBED && ++ time(NULL) - cache->bic_time < BLKID_PROBE_INTERVAL) ++ return 0; + +- while((d = readdir(dir))) { +- int removable = 0; +- dev_t devno; ++ blkid_read_cache(cache); + +-#ifdef _DIRENT_HAVE_D_TYPE +- if (d->d_type != DT_UNKNOWN && d->d_type != DT_LNK) +- continue; ++ evms_probe_all(cache, only_if_new); ++#ifdef VG_DIR ++ lvm_probe_all(cache, only_if_new); + #endif +- if (d->d_name[0] == '.' && +- ((d->d_name[1] == 0) || +- ((d->d_name[1] == '.') && (d->d_name[2] == 0)))) +- continue; +- +- devno = sysfs_devname_to_devno(d->d_name); +- if (!devno) +- continue; +- +- if (sysfs_blkdev_init_path(pc, devno, NULL) == 0 +- && ul_path_read_s32(pc, &removable, "removable") != 0) +- removable = 0; ++ ubi_probe_all(cache, only_if_new); + +- if (removable) +- probe_one(cache, d->d_name, devno, 0, 0, 1); +- } ++ sysfs_probe_all(cache, only_if_new, 0); + +- ul_unref_path(pc); +- closedir(dir); ++ blkid_flush_cache(cache); + return 0; + } + +- + /** + * blkid_probe_all: + * @cache: cache handler +@@ -677,7 +646,7 @@ int blkid_probe_all_removable(blkid_cache cache) + int ret; + + DBG(PROBE, ul_debug("Begin blkid_probe_all_removable()")); +- ret = probe_all_removable(cache); ++ ret = sysfs_probe_all(cache, 0, 1); + DBG(PROBE, ul_debug("End blkid_probe_all_removable() [rc=%d]", ret)); + return ret; + } +-- +1.8.3.1 + diff --git a/backport-libfdisk-add-partition-type-aliases-and-shortcuts.patch b/backport-libfdisk-add-partition-type-aliases-and-shortcuts.patch new file mode 100644 index 0000000000000000000000000000000000000000..8d186fe0559794f8732909a8b836f7bd81342218 --- /dev/null +++ b/backport-libfdisk-add-partition-type-aliases-and-shortcuts.patch @@ -0,0 +1,642 @@ +From f94e753b35cf7a8bdd3a27edb72e094917757334 Mon Sep 17 00:00:00 2001 +From: Karel Zak +Date: Tue, 3 Mar 2020 15:59:49 +0100 +Subject: [PATCH] libfdisk: add partition type aliases and shortcuts + +Now, the type shortcuts are supported for sfdisk scripts only. + +Unfortunately, the current implementation is not generic enough +and it's also fragile as 'E' shortcut is in collision with 0x0E +type for MBR. The another issue is 'L' which makes shortcuts useless +for fdisk where 'L' is used for another purpose in dialogs. + +This patch introduces partition type aliases as extension to +shortcuts. The definition of the shortcut is part of the label +definition and it's not more hardcoded in sfdisk script code. + +This patch also introduces 'Ex' shortcut as replacement for (now +deprecated) 'E'. + +Signed-off-by: Karel Zak +--- + libfdisk/src/dos.c | 16 +++ + libfdisk/src/fdiskP.h | 17 +++ + libfdisk/src/gpt.c | 13 ++ + libfdisk/src/libfdisk.h.in | 36 ++++++ + libfdisk/src/libfdisk.sym | 3 + + libfdisk/src/parttype.c | 236 ++++++++++++++++++++++++++++++------- + libfdisk/src/script.c | 94 ++------------- + 7 files changed, 291 insertions(+), 124 deletions(-) + +diff --git a/libfdisk/src/dos.c b/libfdisk/src/dos.c +index ae06e179d..a79912e8b 100644 +--- a/libfdisk/src/dos.c ++++ b/libfdisk/src/dos.c +@@ -70,6 +70,18 @@ static struct fdisk_parttype dos_parttypes[] = { + #include "pt-mbr-partnames.h" + }; + ++static const struct fdisk_shortcut dos_parttype_cuts[] = ++{ ++ { .shortcut = "L", .alias = "linux", .data = "83" }, ++ { .shortcut = "S", .alias = "swap", .data = "82" }, ++ { .shortcut = "E", .alias = "extended", .data = "05", .deprecated = 1 }, /* collision with 0x0e type */ ++ { .shortcut = "Ex",.alias = "extended", .data = "05" }, /* MBR extended */ ++ { .shortcut = "U", .alias = "uefi", .data = "EF" }, /* UEFI system */ ++ { .shortcut = "R", .alias = "raid", .data = "FD" }, /* Linux RAID */ ++ { .shortcut = "V", .alias = "lvm", .data = "8E" }, /* LVM */ ++ { .shortcut = "X", .alias = "linuxex", .data = "85" } /* Linux extended */ ++}; ++ + #define set_hsc(h,s,c,sector) { \ + s = sector % cxt->geom.sectors + 1; \ + sector /= cxt->geom.sectors; \ +@@ -2556,8 +2568,12 @@ struct fdisk_label *fdisk_new_dos_label(struct fdisk_context *cxt __attribute__ + lb->name = "dos"; + lb->id = FDISK_DISKLABEL_DOS; + lb->op = &dos_operations; ++ + lb->parttypes = dos_parttypes; + lb->nparttypes = ARRAY_SIZE(dos_parttypes) - 1; ++ lb->parttype_cuts = dos_parttype_cuts; ++ lb->nparttype_cuts = ARRAY_SIZE(dos_parttype_cuts); ++ + lb->fields = dos_fields; + lb->nfields = ARRAY_SIZE(dos_fields); + +diff --git a/libfdisk/src/fdiskP.h b/libfdisk/src/fdiskP.h +index ec07f1fc8..f291c08b6 100644 +--- a/libfdisk/src/fdiskP.h ++++ b/libfdisk/src/fdiskP.h +@@ -123,6 +123,17 @@ enum { + #define fdisk_parttype_is_invisible(_x) ((_x) && ((_x)->flags & FDISK_PARTTYPE_INVISIBLE)) + #define fdisk_parttype_is_allocated(_x) ((_x) && ((_x)->flags & FDISK_PARTTYPE_ALLOCATED)) + ++/* ++ * Shortcut (used for partition types) ++ */ ++struct fdisk_shortcut { ++ const char *shortcut; /* shortcut, usually one letter (e.h. "H") */ ++ const char *alias; /* human readable alias (e.g. "home") */ ++ const char *data; /* for example partition type */ ++ ++ unsigned int deprecated : 1; ++}; ++ + struct fdisk_partition { + int refcount; /* reference counter */ + +@@ -278,6 +289,9 @@ struct fdisk_label { + struct fdisk_parttype *parttypes; /* supported partitions types */ + size_t nparttypes; /* number of items in parttypes[] */ + ++ const struct fdisk_shortcut *parttype_cuts; /* partition type shortcuts */ ++ size_t nparttype_cuts; /* number of items in parttype_cuts */ ++ + size_t nparts_max; /* maximal number of partitions */ + size_t nparts_cur; /* number of currently used partitions */ + +@@ -519,4 +533,7 @@ int fdisk_do_wipe(struct fdisk_context *cxt); + int fdisk_has_wipe_area(struct fdisk_context *cxt, uint64_t start, uint64_t size); + int fdisk_check_collisions(struct fdisk_context *cxt); + ++/* parttype.c */ ++const char *fdisk_label_translate_type_shortcut(const struct fdisk_label *lb, char *cut); ++ + #endif /* _LIBFDISK_PRIVATE_H */ +diff --git a/libfdisk/src/gpt.c b/libfdisk/src/gpt.c +index 4915b9a37..25555a395 100644 +--- a/libfdisk/src/gpt.c ++++ b/libfdisk/src/gpt.c +@@ -156,6 +156,16 @@ static struct fdisk_parttype gpt_parttypes[] = + #include "pt-gpt-partnames.h" + }; + ++static const struct fdisk_shortcut gpt_parttype_cuts[] = ++{ ++ { .shortcut = "L", .alias = "linux", .data = "0FC63DAF-8483-4772-8E79-3D69D8477DE4" }, /* Linux */ ++ { .shortcut = "S", .alias = "swap", .data = "0657FD6D-A4AB-43C4-84E5-0933C84B4F4F" }, /* Swap */ ++ { .shortcut = "H", .alias = "home", .data = "933AC7E1-2EB4-4F13-B844-0E14E2AEF915" }, /* Home */ ++ { .shortcut = "U", .alias = "uefi", .data = "C12A7328-F81F-11D2-BA4B-00A0C93EC93B" }, /* UEFI system */ ++ { .shortcut = "R", .alias = "raid", .data = "A19D880F-05FC-4D3B-A006-743F0F84911E" }, /* Linux RAID */ ++ { .shortcut = "V", .alias = "lvm", .data = "E6D6D379-F507-44C2-A23C-238F2A3DF928" } /* LVM */ ++}; ++ + #define alignment_required(_x) ((_x)->grain != (_x)->sector_size) + + /* gpt_entry macros */ +@@ -3134,8 +3144,11 @@ struct fdisk_label *fdisk_new_gpt_label(struct fdisk_context *cxt __attribute__ + lb->name = "gpt"; + lb->id = FDISK_DISKLABEL_GPT; + lb->op = &gpt_operations; ++ + lb->parttypes = gpt_parttypes; + lb->nparttypes = ARRAY_SIZE(gpt_parttypes); ++ lb->parttype_cuts = gpt_parttype_cuts; ++ lb->nparttype_cuts = ARRAY_SIZE(gpt_parttype_cuts); + + lb->fields = gpt_fields; + lb->nfields = ARRAY_SIZE(gpt_fields); +diff --git a/libfdisk/src/libfdisk.h.in b/libfdisk/src/libfdisk.h.in +index 89fad448e..bf05290f9 100644 +--- a/libfdisk/src/libfdisk.h.in ++++ b/libfdisk/src/libfdisk.h.in +@@ -264,7 +264,13 @@ int fdisk_parttype_set_typestr(struct fdisk_parttype *t, const char *str); + int fdisk_parttype_set_code(struct fdisk_parttype *t, int code); + size_t fdisk_label_get_nparttypes(const struct fdisk_label *lb); + struct fdisk_parttype *fdisk_label_get_parttype(const struct fdisk_label *lb, size_t n); ++int fdisk_label_get_parttype_shortcut( ++ const struct fdisk_label *lb, size_t n, ++ const char **typestr, ++ const char **shortcut, ++ const char **alias); + int fdisk_label_has_code_parttypes(const struct fdisk_label *lb); ++int fdisk_label_has_parttypes_shortcuts(const struct fdisk_label *lb); + struct fdisk_parttype *fdisk_label_get_parttype_from_code( + const struct fdisk_label *lb, + unsigned int code); +@@ -277,6 +283,36 @@ struct fdisk_parttype *fdisk_copy_parttype(const struct fdisk_parttype *type); + struct fdisk_parttype *fdisk_label_parse_parttype( + const struct fdisk_label *lb, + const char *str); ++struct fdisk_parttype *fdisk_label_advparse_parttype( ++ const struct fdisk_label *lb, ++ const char *str, ++ int flags); ++ ++/** ++ * fdisk_parttype_parser_flags: ++ * @FDISK_PARTTYPE_PARSE_DATA: parse hex or UUID from string ++ * @FDISK_PARTTYPE_PARSE_DATALAST: try hex or UUID as the last possibility (don't use!) ++ * @FDISK_PARTTYPE_PARSE_SHORTCUT: try input interpret as type shortcut (e.g 'L' for linux partition) ++ * @FDISK_PARTTYPE_PARSE_ALIAS: try input interpret as type alias (e.g. 'linux' for linux partition) ++ * @FDISK_PARTTYPE_PARSE_DEPRECATED: accept also deprecated aliases and shortcuts ++ * @FDISK_PARTTYPE_PARSE_DEFAULT: recommended flags for new code ++ * @FDISK_PARTTYPE_PARSE_NOUNKNOWN: ignore unknown types ++ */ ++enum fdisk_parttype_parser_flags { ++ FDISK_PARTTYPE_PARSE_DATA = (1 << 1), ++ FDISK_PARTTYPE_PARSE_DATALAST = (1 << 2), ++ FDISK_PARTTYPE_PARSE_SHORTCUT = (1 << 3), ++ FDISK_PARTTYPE_PARSE_ALIAS = (1 << 4), ++ FDISK_PARTTYPE_PARSE_DEPRECATED = (1 << 5), ++ FDISK_PARTTYPE_PARSE_NOUNKNOWN = (1 << 6), ++ FDISK_PARTTYPE_PARSE_SEQNUM = (1 << 7), ++ ++ FDISK_PARTTYPE_PARSE_DEFAULT = (FDISK_PARTTYPE_PARSE_DATA | \ ++ FDISK_PARTTYPE_PARSE_SHORTCUT | \ ++ FDISK_PARTTYPE_PARSE_ALIAS | \ ++ FDISK_PARTTYPE_PARSE_SEQNUM ) ++}; ++ + const char *fdisk_parttype_get_string(const struct fdisk_parttype *t); + unsigned int fdisk_parttype_get_code(const struct fdisk_parttype *t); + const char *fdisk_parttype_get_name(const struct fdisk_parttype *t); +diff --git a/libfdisk/src/libfdisk.sym b/libfdisk/src/libfdisk.sym +index 96fcadd..4a5ba0b 100644 +--- a/libfdisk/src/libfdisk.sym ++++ b/libfdisk/src/libfdisk.sym +@@ -307,4 +307,7 @@ FDISK_2.33 { + FDISK_2.35 { + fdisk_script_set_table; + fdisk_assign_device_by_fd; ++ fdisk_label_has_parttypes_shortcuts; ++ fdisk_label_advparse_parttype; ++ fdisk_label_get_parttype_shortcut; + } FDISK_2.33; +diff --git a/libfdisk/src/parttype.c b/libfdisk/src/parttype.c +index d5ad434f0..36d12216d 100644 +--- a/libfdisk/src/parttype.c ++++ b/libfdisk/src/parttype.c +@@ -145,6 +145,41 @@ struct fdisk_parttype *fdisk_label_get_parttype(const struct fdisk_label *lb, si + return &lb->parttypes[n]; + } + ++/** ++ * fdisk_label_get_parttype_shortcut: ++ * @lb: label ++ * @n: number ++ * @typestr: returns type as string ++ * @shortcut: returns type shortcut string ++ * @alias: returns type alias string ++ * ++ * Returns: return 0 on success, <0 on error, 2 for deprecated alias, 1 for @n out of range ++ * ++ * Since: v2.36 ++ */ ++int fdisk_label_get_parttype_shortcut(const struct fdisk_label *lb, size_t n, ++ const char **typestr, const char **shortcut, const char **alias) ++{ ++ const struct fdisk_shortcut *sc; ++ ++ if (!lb) ++ return -EINVAL; ++ if (n >= lb->nparttype_cuts) ++ return 1; ++ ++ sc = &lb->parttype_cuts[n]; ++ if (typestr) ++ *typestr = sc->data; ++ if (shortcut) ++ *shortcut = sc->shortcut; ++ if (alias) ++ *alias = sc->alias; ++ ++ return sc->deprecated == 1 ? 2 : 0; ++ ++} ++ ++ + /** + * fdisk_label_has_code_parttypes: + * @lb: label +@@ -161,6 +196,20 @@ int fdisk_label_has_code_parttypes(const struct fdisk_label *lb) + return 1; + } + ++/** ++ * fdisk_label_has_parttypes_shortcuts ++ * @lb: label ++ * ++ * Returns: 1 if the label support shortuts/aliases for partition types or 0. ++ * ++ * Since: 2.36 ++ */ ++int fdisk_label_has_parttypes_shortcuts(const struct fdisk_label *lb) ++{ ++ assert(lb); ++ return lb->nparttype_cuts ? 1 : 0; ++} ++ + + /** + * fdisk_label_get_parttype_from_code: +@@ -266,79 +315,186 @@ struct fdisk_parttype *fdisk_copy_parttype(const struct fdisk_parttype *type) + return t; + } + +-/** +- * fdisk_label_parse_parttype: +- * @lb: label +- * @str: string to parse from +- * +- * Parses partition type from @str according to the label. The function returns +- * a pointer to static table of the partition types, or newly allocated +- * partition type for unknown types (see fdisk_parttype_is_unknown(). It's +- * safe to call fdisk_unref_parttype() for all results. +- * +- * Returns: pointer to type or NULL on error. +- */ +-struct fdisk_parttype *fdisk_label_parse_parttype( ++static struct fdisk_parttype *parttype_from_data( + const struct fdisk_label *lb, +- const char *str) ++ const char *str, ++ unsigned int *xcode, ++ int use_seqnum) + { + struct fdisk_parttype *types, *ret = NULL; + char *end = NULL; + + assert(lb); ++ assert(str); + ++ if (xcode) ++ *xcode = 0; + if (!lb->nparttypes) + return NULL; + +- DBG(LABEL, ul_debugobj(lb, "parsing '%s' (%s) partition type", +- str, lb->name)); ++ DBG(LABEL, ul_debugobj(lb, " parsing '%s' data", str)); + types = lb->parttypes; + + if (types[0].typestr == NULL) { +- unsigned int code = 0; ++ unsigned int code; + +- DBG(LABEL, ul_debugobj(lb, " parsing hex")); ++ DBG(LABEL, ul_debugobj(lb, " +hex")); + + errno = 0; + code = strtol(str, &end, 16); + + if (errno || *end != '\0') { +- DBG(LABEL, ul_debugobj(lb, "parsing failed: %m")); ++ DBG(LABEL, ul_debugobj(lb, " failed: %m")); + return NULL; + } ++ if (xcode) ++ *xcode = code; + ret = fdisk_label_get_parttype_from_code(lb, code); +- if (ret) +- goto done; +- +- ret = fdisk_new_unknown_parttype(code, NULL); + } else { +- int i; +- +- DBG(LABEL, ul_debugobj(lb, " parsing string")); ++ DBG(LABEL, ul_debugobj(lb, " +string")); + + /* maybe specified by type string (e.g. UUID) */ + ret = fdisk_label_get_parttype_from_string(lb, str); +- if (ret) +- goto done; + +- /* maybe specified by order number */ +- errno = 0; +- i = strtol(str, &end, 0); +- if (errno == 0 && *end == '\0' && i > 0 +- && i - 1 < (int) lb->nparttypes) { +- ret = &types[i - 1]; +- goto done; +- } ++ if (!ret) { ++ /* maybe specified by order number */ ++ int i; ++ ++ errno = 0; ++ i = strtol(str, &end, 0); + +- ret = fdisk_new_unknown_parttype(0, str); ++ if (use_seqnum && errno == 0 ++ && *end == '\0' && i > 0 ++ && i - 1 < (int) lb->nparttypes) ++ ret = &types[i - 1]; ++ } + } + +-done: +- DBG(PARTTYPE, ul_debugobj(ret, "returns parsed '%s' [%s] partition type", +- ret->name, ret->typestr ? : "")); ++ if (ret) ++ DBG(PARTTYPE, ul_debugobj(ret, " result '%s'", ret->name)); + return ret; + } + ++static struct fdisk_parttype *parttype_from_shortcut( ++ const struct fdisk_label *lb, ++ const char *str, int deprecated) ++{ ++ size_t i; ++ ++ DBG(LABEL, ul_debugobj(lb, " parsing '%s' shortcut", str)); ++ ++ for (i = 0; i < lb->nparttype_cuts; i++) { ++ const struct fdisk_shortcut *sc = &lb->parttype_cuts[i]; ++ ++ if (sc->deprecated && !deprecated) ++ continue; ++ if (sc->shortcut && strcmp(sc->shortcut, str) == 0) ++ return parttype_from_data(lb, sc->data, NULL, 0); ++ } ++ return NULL; ++} ++ ++static struct fdisk_parttype *parttype_from_alias( ++ const struct fdisk_label *lb, ++ const char *str, int deprecated) ++{ ++ size_t i; ++ ++ DBG(LABEL, ul_debugobj(lb, " parsing '%s' alias", str)); ++ ++ for (i = 0; i < lb->nparttype_cuts; i++) { ++ const struct fdisk_shortcut *sc = &lb->parttype_cuts[i]; ++ ++ if (sc->deprecated && !deprecated) ++ continue; ++ if (sc->alias && strcmp(sc->alias, str) == 0) ++ return parttype_from_data(lb, sc->data, NULL, 0); ++ } ++ return NULL; ++} ++ ++/** ++ * fdisk_label_advparse_parttype: ++ * @lb: label ++ * @str: string to parse from ++ * @flags: FDISK_PARTTYPE_PARSE_* ++ * ++ * This function is advanced partition types parser. It parses partition type ++ * from @str according to the label. The function returns a pointer to static ++ * table of the partition types, or newly allocated partition type for unknown ++ * types (see fdisk_parttype_is_unknown(). It's safe to call fdisk_unref_parttype() ++ * for all results. ++ * ++ * The @str may be type data (hex code or UUID), alias or shortcut. For GPT ++ * also sequence number of the type in the list of the supported types. ++ * ++ * Returns: pointer to type or NULL on error. ++ */ ++struct fdisk_parttype *fdisk_label_advparse_parttype( ++ const struct fdisk_label *lb, ++ const char *str, ++ int flags) ++{ ++ struct fdisk_parttype *res = NULL; ++ unsigned int code = 0; ++ ++ if (!lb->nparttypes) ++ return NULL; ++ ++ DBG(LABEL, ul_debugobj(lb, "parsing '%s' (%s) type", str, lb->name)); ++ ++ if ((flags & FDISK_PARTTYPE_PARSE_DATA) ++ && !(flags & FDISK_PARTTYPE_PARSE_DATALAST)) ++ res = parttype_from_data(lb, str, &code, ++ flags & FDISK_PARTTYPE_PARSE_SEQNUM); ++ ++ if (!res && (flags & FDISK_PARTTYPE_PARSE_ALIAS)) ++ res = parttype_from_alias(lb, str, ++ flags & FDISK_PARTTYPE_PARSE_DEPRECATED); ++ ++ if (!res && (flags & FDISK_PARTTYPE_PARSE_SHORTCUT)) ++ res = parttype_from_shortcut(lb, str, ++ flags & FDISK_PARTTYPE_PARSE_DEPRECATED); ++ ++ if (!res && (flags & FDISK_PARTTYPE_PARSE_DATA) ++ && (flags & FDISK_PARTTYPE_PARSE_DATALAST)) ++ res = parttype_from_data(lb, str, &code, ++ flags & FDISK_PARTTYPE_PARSE_SEQNUM); ++ ++ if (!res && !(flags & FDISK_PARTTYPE_PARSE_NOUNKNOWN)) { ++ if (lb->parttypes[0].typestr) ++ res = fdisk_new_unknown_parttype(0, str); ++ else ++ res = fdisk_new_unknown_parttype(code, NULL); ++ } ++ ++ if (res) ++ DBG(PARTTYPE, ul_debugobj(res, "returns parsed '%s' [%s] partition type", ++ res->name, res->typestr ? : "")); ++ return res; ++} ++ ++/** ++ * fdisk_label_parse_parttype: ++ * @lb: label ++ * @str: string to parse from (type name, UUID, etc.) ++ * ++ * Parses partition type from @str according to the label. The function returns ++ * a pointer to static table of the partition types, or newly allocated ++ * partition type for unknown types (see fdisk_parttype_is_unknown(). It's ++ * safe to call fdisk_unref_parttype() for all results. ++ * ++ * Note that for GPT it accepts sequence number of UUID. ++ * ++ * Returns: pointer to type or NULL on error. ++ */ ++struct fdisk_parttype *fdisk_label_parse_parttype( ++ const struct fdisk_label *lb, ++ const char *str) ++{ ++ return fdisk_label_advparse_parttype(lb, str, FDISK_PARTTYPE_PARSE_DATA); ++} ++ + /** + * fdisk_parttype_get_string: + * @t: type +diff --git a/libfdisk/src/script.c b/libfdisk/src/script.c +index 6f66f88b9..e73c8dcdb 100644 +--- a/libfdisk/src/script.c ++++ b/libfdisk/src/script.c +@@ -61,9 +61,6 @@ struct fdisk_script { + force_label : 1; /* label: specified */ + }; + +-static struct fdisk_parttype *translate_type_shortcuts(struct fdisk_script *dp, char *str); +- +- + static void fdisk_script_free_header(struct fdisk_scriptheader *fi) + { + if (!fi) +@@ -969,6 +966,11 @@ static int partno_from_devname(char *s) + return pno - 1; + } + ++#define FDISK_SCRIPT_PARTTYPE_PARSE_FLAGS \ ++ (FDISK_PARTTYPE_PARSE_DATA | FDISK_PARTTYPE_PARSE_DATALAST | \ ++ FDISK_PARTTYPE_PARSE_SHORTCUT | FDISK_PARTTYPE_PARSE_ALIAS | \ ++ FDISK_PARTTYPE_PARSE_DEPRECATED) ++ + /* dump format + * : start=, size=, type=, ... + */ +@@ -1069,19 +1071,14 @@ static int parse_line_nameval(struct fdisk_script *dp, char *s) + if (rc) + break; + +- pa->type = translate_type_shortcuts(dp, type); +- if (!pa->type) +- pa->type = fdisk_label_parse_parttype( +- script_get_label(dp), type); ++ pa->type = fdisk_label_advparse_parttype(script_get_label(dp), ++ type, FDISK_SCRIPT_PARTTYPE_PARSE_FLAGS); + free(type); + + if (!pa->type) { + rc = -EINVAL; +- fdisk_unref_parttype(pa->type); +- pa->type = NULL; + break; + } +- + } else { + DBG(SCRIPT, ul_debugobj(dp, "script parse error: unknown field '%s'", p)); + rc = -EINVAL; +@@ -1098,71 +1095,6 @@ static int parse_line_nameval(struct fdisk_script *dp, char *s) + return rc; + } + +-/* original sfdisk supports partition types shortcuts like 'L' = Linux native +- */ +-static struct fdisk_parttype *translate_type_shortcuts(struct fdisk_script *dp, char *str) +-{ +- struct fdisk_label *lb; +- const char *type = NULL; +- +- if (strlen(str) != 1) +- return NULL; +- +- lb = script_get_label(dp); +- if (!lb) +- return NULL; +- +- if (lb->id == FDISK_DISKLABEL_DOS) { +- switch (*str) { +- case 'L': /* Linux */ +- type = "83"; +- break; +- case 'S': /* Swap */ +- type = "82"; +- break; +- case 'E': /* Dos extended */ +- type = "05"; +- break; +- case 'X': /* Linux extended */ +- type = "85"; +- break; +- case 'U': /* UEFI system */ +- type = "EF"; +- break; +- case 'R': /* Linux RAID */ +- type = "FD"; +- break; +- case 'V': /* LVM */ +- type = "8E"; +- break; +- +- } +- } else if (lb->id == FDISK_DISKLABEL_GPT) { +- switch (*str) { +- case 'L': /* Linux */ +- type = "0FC63DAF-8483-4772-8E79-3D69D8477DE4"; +- break; +- case 'S': /* Swap */ +- type = "0657FD6D-A4AB-43C4-84E5-0933C84B4F4F"; +- break; +- case 'H': /* Home */ +- type = "933AC7E1-2EB4-4F13-B844-0E14E2AEF915"; +- break; +- case 'U': /* UEFI system */ +- type = "C12A7328-F81F-11D2-BA4B-00A0C93EC93B"; +- break; +- case 'R': /* Linux RAID */ +- type = "A19D880F-05FC-4D3B-A006-743F0F84911E"; +- break; +- case 'V': /* LVM */ +- type = "E6D6D379-F507-44C2-A23C-238F2A3DF928"; +- break; +- } +- } +- +- return type ? fdisk_label_parse_parttype(lb, type) : NULL; +-} +- + #define TK_PLUS 1 + #define TK_MINUS -1 + +@@ -1257,18 +1189,12 @@ static int parse_line_valcommas(struct fdisk_script *dp, char *s) + if (rc) + break; + +- pa->type = translate_type_shortcuts(dp, str); +- if (!pa->type) +- pa->type = fdisk_label_parse_parttype( +- script_get_label(dp), str); ++ pa->type = fdisk_label_advparse_parttype(script_get_label(dp), ++ str, FDISK_SCRIPT_PARTTYPE_PARSE_FLAGS); + free(str); + +- if (!pa->type) { ++ if (!pa->type) + rc = -EINVAL; +- fdisk_unref_parttype(pa->type); +- pa->type = NULL; +- break; +- } + break; + case ITEM_BOOTABLE: + if (*p == ',' || *p == ';') diff --git a/backport-libfdisk-another-parse_line-nameval-cleanup.patch b/backport-libfdisk-another-parse_line-nameval-cleanup.patch new file mode 100644 index 0000000000000000000000000000000000000000..5b3ac2dbd71cdc77df5b3526e5193ae502ce35c6 --- /dev/null +++ b/backport-libfdisk-another-parse_line-nameval-cleanup.patch @@ -0,0 +1,63 @@ +From d8f35960ae0daa5d8b8231d22a6e967f5fcadb31 Mon Sep 17 00:00:00 2001 +From: Karel Zak +Date: Thu, 13 Aug 2020 10:13:01 +0200 +Subject: [PATCH] libfdisk: another parse_line_nameval() cleanup + +--- + libfdisk/src/script.c | 23 +++++++++++++---------- + 1 file changed, 13 insertions(+), 10 deletions(-) + +diff --git a/libfdisk/src/script.c b/libfdisk/src/script.c +index 81d425945..4d9835f59 100644 +--- a/libfdisk/src/script.c ++++ b/libfdisk/src/script.c +@@ -939,7 +939,7 @@ static int next_number(char **s, uint64_t *num, int *power) + + static int next_string(char **s, char **str) + { +- char *tk; ++ char *tk, *p = NULL; + int rc = -EINVAL; + + assert(s); +@@ -947,9 +947,11 @@ static int next_string(char **s, char **str) + + tk = next_token(s); + if (tk) { +- *str = strdup(tk); +- rc = !*str ? -ENOMEM : 0; ++ p = strdup(tk); ++ rc = p ? 0 : -ENOMEM; + } ++ ++ *str = p; + return rc; + } + +@@ -1086,18 +1088,19 @@ static int parse_line_nameval(struct fdisk_script *dp, char *s) + !strncasecmp(p, "Id=", 3)) { /* backward compatibility */ + char *type = NULL; + ++ fdisk_unref_parttype(pa->type); ++ pa->type = NULL; ++ + p += ((*p == 'I' || *p == 'i') ? 3 : 5); /* "Id=", "type=" */ + + rc = next_string(&p, &type); +- if (rc) +- break; +- +- fdisk_unref_parttype(pa->type); +- pa->type = fdisk_label_advparse_parttype(script_get_label(dp), ++ if (rc == 0) { ++ pa->type = fdisk_label_advparse_parttype(script_get_label(dp), + type, FDISK_SCRIPT_PARTTYPE_PARSE_FLAGS); ++ if (!pa->type) ++ rc = -EINVAL; ++ } + free(type); +- if (!pa->type) +- rc = -EINVAL; + } else { + DBG(SCRIPT, ul_debugobj(dp, "script parse error: unknown field '%s'", p)); + rc = -EINVAL; diff --git a/backport-libfdisk-fix-typo-from-255f5f4c770ebd46a38b58975bd33.patch b/backport-libfdisk-fix-typo-from-255f5f4c770ebd46a38b58975bd33.patch new file mode 100644 index 0000000000000000000000000000000000000000..aedf120d79bb5db9b55992812c778897027780f1 --- /dev/null +++ b/backport-libfdisk-fix-typo-from-255f5f4c770ebd46a38b58975bd33.patch @@ -0,0 +1,24 @@ +From 3b87a9af494b4ecc2ed3aa544f1a2f8df6789354 Mon Sep 17 00:00:00 2001 +From: Karel Zak +Date: Wed, 12 Aug 2020 19:48:47 +0200 +Subject: [PATCH] libfdisk: fix typo from + 255f5f4c770ebd46a38b58975bd33e33ae87ed24 + +Signed-off-by: Karel Zak +--- + libfdisk/src/parttype.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/libfdisk/src/parttype.c b/libfdisk/src/parttype.c +index ec5debca7..72c5e3613 100644 +--- a/libfdisk/src/parttype.c ++++ b/libfdisk/src/parttype.c +@@ -438,7 +438,7 @@ struct fdisk_parttype *fdisk_label_advparse_parttype( + struct fdisk_parttype *res = NULL; + unsigned int code = 0; + +- if (!lb || lb->nparttypes) ++ if (!lb || !lb->nparttypes) + return NULL; + + DBG(LABEL, ul_debugobj(lb, "parsing '%s' (%s) type", str, lb->name)); diff --git a/backport-libfdisk-make-fdisk_partname-more-robust.patch b/backport-libfdisk-make-fdisk_partname-more-robust.patch new file mode 100644 index 0000000000000000000000000000000000000000..89990e86973820441eb087cf0de6a6553ab1a3f6 --- /dev/null +++ b/backport-libfdisk-make-fdisk_partname-more-robust.patch @@ -0,0 +1,22 @@ +From 9f03ad60e58f7bdcac6a1046471a3374550ee384 Mon Sep 17 00:00:00 2001 +From: Karel Zak +Date: Thu, 13 Aug 2020 10:12:01 +0200 +Subject: [PATCH] libfdisk: make fdisk_partname() more robust + +--- + libfdisk/src/utils.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/libfdisk/src/utils.c b/libfdisk/src/utils.c +index 6056e7f1f..38ad23393 100644 +--- a/libfdisk/src/utils.c ++++ b/libfdisk/src/utils.c +@@ -142,7 +142,7 @@ char *fdisk_partname(const char *dev, size_t partno) + + /* devfs kludge - note: fdisk partition names are not supposed + to equal kernel names, so there is no reason to do this */ +- if (strcmp(dev + w - 4, "disc") == 0) { ++ if (endswith(dev, "disc")) { + w -= 4; + p = "part"; + } diff --git a/backport-libfdisk-script-don-t-use-sector-size-if-not-specifi.patch b/backport-libfdisk-script-don-t-use-sector-size-if-not-specifi.patch new file mode 100644 index 0000000000000000000000000000000000000000..a36a28e6db8a71c8ccdc1ca1d48e08251f1ef895 --- /dev/null +++ b/backport-libfdisk-script-don-t-use-sector-size-if-not-specifi.patch @@ -0,0 +1,78 @@ +From 8bbc11f12ffb7adfc188b7b8885e74d40bd54713 Mon Sep 17 00:00:00 2001 +From: Karel Zak +Date: Wed, 12 Aug 2020 15:59:38 +0200 +Subject: [PATCH] libfdisk: (script) don't use sector size if not specified + +This is probably bad script API use, but better be safe than sorry. + +Signed-off-by: Karel Zak +--- + libfdisk/src/script.c | 30 ++++++++++++++++++++++++------ + 1 file changed, 24 insertions(+), 6 deletions(-) + +diff --git a/libfdisk/src/script.c b/libfdisk/src/script.c +index d18ba5737..2a3d1b818 100644 +--- a/libfdisk/src/script.c ++++ b/libfdisk/src/script.c +@@ -1032,8 +1032,13 @@ static int parse_line_nameval(struct fdisk_script *dp, char *s) + p += 6; + rc = next_number(&p, &num, &pow); + if (!rc) { +- if (pow) /* specified as */ ++ if (pow) { /* specified as */ ++ if (!dp->cxt->sector_size) { ++ rc = -EINVAL; ++ break; ++ } + num /= dp->cxt->sector_size; ++ } + fdisk_partition_set_start(pa, num); + fdisk_partition_start_follow_default(pa, 0); + } +@@ -1043,9 +1048,13 @@ static int parse_line_nameval(struct fdisk_script *dp, char *s) + p += 5; + rc = next_number(&p, &num, &pow); + if (!rc) { +- if (pow) /* specified as */ ++ if (pow) { /* specified as */ ++ if (!dp->cxt->sector_size) { ++ rc = -EINVAL; ++ break; ++ } + num /= dp->cxt->sector_size; +- else /* specified as number of sectors */ ++ } else /* specified as number of sectors */ + fdisk_partition_size_explicit(pa, 1); + fdisk_partition_set_size(pa, num); + fdisk_partition_end_follow_default(pa, 0); +@@ -1159,8 +1168,13 @@ static int parse_line_valcommas(struct fdisk_script *dp, char *s) + + rc = next_number(&p, &num, &pow); + if (!rc) { +- if (pow) /* specified as */ ++ if (pow) { /* specified as */ ++ if (!dp->cxt->sector_size) { ++ rc = -EINVAL; ++ break; ++ } + num /= dp->cxt->sector_size; ++ } + fdisk_partition_set_start(pa, num); + pa->movestart = sign == TK_MINUS ? FDISK_MOVE_DOWN : + sign == TK_PLUS ? FDISK_MOVE_UP : +@@ -1179,9 +1193,13 @@ static int parse_line_valcommas(struct fdisk_script *dp, char *s) + int pow = 0; + rc = next_number(&p, &num, &pow); + if (!rc) { +- if (pow) /* specified as */ ++ if (pow) { /* specified as */ ++ if (!dp->cxt->sector_size) { ++ rc = -EINVAL; ++ break; ++ } + num /= dp->cxt->sector_size; +- else /* specified as number of sectors */ ++ } else /* specified as number of sectors */ + fdisk_partition_size_explicit(pa, 1); + fdisk_partition_set_size(pa, num); + pa->resize = sign == TK_MINUS ? FDISK_RESIZE_REDUCE : diff --git a/backport-libfdisk-script-fix-possible-memory-leaks.patch b/backport-libfdisk-script-fix-possible-memory-leaks.patch new file mode 100644 index 0000000000000000000000000000000000000000..87ad5ac2cf1419fa0ce47ccaedecb9e71a960137 --- /dev/null +++ b/backport-libfdisk-script-fix-possible-memory-leaks.patch @@ -0,0 +1,75 @@ +From 678d03cc8a9c665ba989b098a9be903ede72f554 Mon Sep 17 00:00:00 2001 +From: Karel Zak +Date: Thu, 13 Aug 2020 13:48:28 +0200 +Subject: [PATCH] libfdisk: (script) fix possible memory leaks + +Signed-off-by: Karel Zak +--- + libfdisk/src/script.c | 11 ++++++++++- + 1 file changed, 10 insertions(+), 1 deletion(-) + +diff --git a/libfdisk/src/script.c b/libfdisk/src/script.c +index 4d9835f59..74ff43b73 100644 +--- a/libfdisk/src/script.c ++++ b/libfdisk/src/script.c +@@ -640,6 +640,7 @@ static int write_file_json(struct fdisk_script *dp, FILE *f) + fputs("\"node\":", f); + fputs_quoted_json(p, f); + nvars++; ++ free(p); + } + + if (fdisk_partition_has_start(pa)) { +@@ -741,6 +742,7 @@ static int write_file_sfdisk(struct fdisk_script *dp, FILE *f) + if (p) { + DBG(SCRIPT, ul_debugobj(dp, "write %s entry", p)); + fprintf(f, "%s :", p); ++ free(p); + } else + fprintf(f, "%zu :", pa->partno + 1); + +@@ -1072,14 +1074,17 @@ static int parse_line_nameval(struct fdisk_script *dp, char *s) + + } else if (!strncasecmp(p, "attrs=", 6)) { + p += 6; ++ free(pa->attrs); + rc = next_string(&p, &pa->attrs); + + } else if (!strncasecmp(p, "uuid=", 5)) { + p += 5; ++ free(pa->uuid); + rc = next_string(&p, &pa->uuid); + + } else if (!strncasecmp(p, "name=", 5)) { + p += 5; ++ free(pa->name); + rc = next_string(&p, &pa->name); + if (!rc) + unhexmangle_string(pa->name); +@@ -1128,7 +1133,7 @@ static int parse_line_nameval(struct fdisk_script *dp, char *s) + static int parse_line_valcommas(struct fdisk_script *dp, char *s) + { + int rc = 0; +- char *p = s, *str; ++ char *p = s; + struct fdisk_partition *pa; + enum { ITEM_START, ITEM_SIZE, ITEM_TYPE, ITEM_BOOTABLE }; + int item = -1; +@@ -1213,6 +1218,9 @@ static int parse_line_valcommas(struct fdisk_script *dp, char *s) + } + break; + case ITEM_TYPE: ++ { ++ char *str = NULL; ++ + if (*p == ',' || *p == ';' || alone_sign(sign, p)) + break; /* use default type */ + +@@ -1227,6 +1235,7 @@ static int parse_line_valcommas(struct fdisk_script *dp, char *s) + if (!pa->type) + rc = -EINVAL; + break; ++ } + case ITEM_BOOTABLE: + if (*p == ',' || *p == ';') + break; diff --git a/backport-libfdisk-script-fix-possible-partno-overflow.patch b/backport-libfdisk-script-fix-possible-partno-overflow.patch new file mode 100644 index 0000000000000000000000000000000000000000..b6437977824b7250c28391ebb9d0e1bcd0f8e3fb --- /dev/null +++ b/backport-libfdisk-script-fix-possible-partno-overflow.patch @@ -0,0 +1,42 @@ +From 1f50296c0f2384f474e3bbd92926edea53c3bace Mon Sep 17 00:00:00 2001 +From: Karel Zak +Date: Fri, 14 Aug 2020 11:13:50 +0200 +Subject: [PATCH] libfdisk: (script) fix possible partno overflow + +Addresses: https://oss-fuzz.com/testcase-detail/5740890480705536 +Signed-off-by: Karel Zak +--- + libfdisk/src/script.c | 11 ++++++++--- + 1 file changed, 8 insertions(+), 3 deletions(-) + +diff --git a/libfdisk/src/script.c b/libfdisk/src/script.c +index 74ff43b73..37a5a3edc 100644 +--- a/libfdisk/src/script.c ++++ b/libfdisk/src/script.c +@@ -959,7 +959,7 @@ static int next_string(char **s, char **str) + + static int partno_from_devname(char *s) + { +- int pno; ++ intmax_t num; + size_t sz; + char *end, *p; + +@@ -975,10 +975,15 @@ static int partno_from_devname(char *s) + return -1; + end = NULL; + errno = 0; +- pno = strtol(p, &end, 10); ++ num = strtol(p, &end, 10); + if (errno || !end || p == end) + return -1; +- return pno - 1; ++ ++ if (num < INT32_MIN || num > INT32_MAX) { ++ errno = ERANGE; ++ return -1; ++ } ++ return num - 1; + } + + #define FDISK_SCRIPT_PARTTYPE_PARSE_FLAGS \ diff --git a/backport-libfdisk-script-make-sure-label-is-specified.patch b/backport-libfdisk-script-make-sure-label-is-specified.patch new file mode 100644 index 0000000000000000000000000000000000000000..2a01a28906e445984e1b9cee8bbdf210d39ac743 --- /dev/null +++ b/backport-libfdisk-script-make-sure-label-is-specified.patch @@ -0,0 +1,68 @@ +From 255f5f4c770ebd46a38b58975bd33e33ae87ed24 Mon Sep 17 00:00:00 2001 +From: Karel Zak +Date: Wed, 12 Aug 2020 15:52:53 +0200 +Subject: [PATCH] libfdisk: (script) make sure label is specified + +and unref type if already specified (unlikely, but be paranoid) + +Signed-off-by: Karel Zak +--- + libfdisk/src/parttype.c | 2 +- + libfdisk/src/script.c | 10 ++++------ + 2 files changed, 5 insertions(+), 7 deletions(-) + +diff --git a/libfdisk/src/parttype.c b/libfdisk/src/parttype.c +index e3eb0cffa..ec5debca7 100644 +--- a/libfdisk/src/parttype.c ++++ b/libfdisk/src/parttype.c +@@ -438,7 +438,7 @@ struct fdisk_parttype *fdisk_label_advparse_parttype( + struct fdisk_parttype *res = NULL; + unsigned int code = 0; + +- if (!lb->nparttypes) ++ if (!lb || lb->nparttypes) + return NULL; + + DBG(LABEL, ul_debugobj(lb, "parsing '%s' (%s) type", str, lb->name)); +diff --git a/libfdisk/src/script.c b/libfdisk/src/script.c +index 051fa326e..d18ba5737 100644 +--- a/libfdisk/src/script.c ++++ b/libfdisk/src/script.c +@@ -1075,7 +1075,7 @@ static int parse_line_nameval(struct fdisk_script *dp, char *s) + + } else if (!strncasecmp(p, "type=", 5) || + !strncasecmp(p, "Id=", 3)) { /* backward compatibility */ +- char *type; ++ char *type = NULL; + + p += ((*p == 'I' || *p == 'i') ? 3 : 5); /* "Id=", "type=" */ + +@@ -1083,14 +1083,12 @@ static int parse_line_nameval(struct fdisk_script *dp, char *s) + if (rc) + break; + ++ fdisk_unref_parttype(pa->type); + pa->type = fdisk_label_advparse_parttype(script_get_label(dp), + type, FDISK_SCRIPT_PARTTYPE_PARSE_FLAGS); + free(type); +- +- if (!pa->type) { ++ if (!pa->type) + rc = -EINVAL; +- break; +- } + } else { + DBG(SCRIPT, ul_debugobj(dp, "script parse error: unknown field '%s'", p)); + rc = -EINVAL; +@@ -1201,10 +1199,10 @@ static int parse_line_valcommas(struct fdisk_script *dp, char *s) + if (rc) + break; + ++ fdisk_unref_parttype(pa->type); + pa->type = fdisk_label_advparse_parttype(script_get_label(dp), + str, FDISK_SCRIPT_PARTTYPE_PARSE_FLAGS); + free(str); +- + if (!pa->type) + rc = -EINVAL; + break; diff --git a/backport-libmount-fix-tab-parser-for-badly-terminated-lines.patch b/backport-libmount-fix-tab-parser-for-badly-terminated-lines.patch new file mode 100644 index 0000000000000000000000000000000000000000..e3dea87cb863607891dfe04d32025633609140c1 --- /dev/null +++ b/backport-libmount-fix-tab-parser-for-badly-terminated-lines.patch @@ -0,0 +1,66 @@ +From 72f783d0ea5297e3fab22a93574aa63f421c5f69 Mon Sep 17 00:00:00 2001 +From: Karel Zak +Date: Mon, 17 Aug 2020 16:33:59 +0200 +Subject: [PATCH] libmount: fix tab parser for badly terminated lines + +Signed-off-by: Karel Zak +--- + libmount/src/tab_parse.c | 26 +++++++++++--------------- + 1 file changed, 11 insertions(+), 15 deletions(-) + +diff --git a/libmount/src/tab_parse.c b/libmount/src/tab_parse.c +index fa2d31b81..329987bcb 100644 +--- a/libmount/src/tab_parse.c ++++ b/libmount/src/tab_parse.c +@@ -481,7 +481,7 @@ static int is_terminated_by_blank(const char *str) + if (p == str) + return 1; /* only '\n' */ + p--; +- while (p >= str && (*p == ' ' || *p == '\t')) ++ while (p > str && (*p == ' ' || *p == '\t')) + p--; + return *p == '\n' ? 1 : 0; + } +@@ -553,22 +553,16 @@ static int mnt_table_parse_next(struct libmnt_parser *pa, + pa->line++; + s = strchr(pa->buf, '\n'); + if (!s) { ++ DBG(TAB, ul_debugobj(tb, "%s:%zu: no final newline", ++ pa->filename, pa->line)); ++ + /* Missing final newline? Otherwise an extremely */ + /* long line - assume file was corrupted */ +- if (feof(pa->f)) { +- DBG(TAB, ul_debugobj(tb, +- "%s: no final newline", pa->filename)); +- s = strchr(pa->buf, '\0'); +- } else { +- DBG(TAB, ul_debugobj(tb, +- "%s:%zu: missing newline at line", +- pa->filename, pa->line)); +- goto err; +- } +- } ++ if (feof(pa->f)) ++ s = memchr(pa->buf, '\0', pa->bufsiz); + + /* comments parser */ +- if (tb->comms ++ } else if (tb->comms + && (tb->fmt == MNT_FMT_GUESS || tb->fmt == MNT_FMT_FSTAB) + && is_comment_line(pa->buf)) { + do { +@@ -584,9 +578,11 @@ static int mnt_table_parse_next(struct libmnt_parser *pa, + + } + ++ if (!s) ++ goto err; + *s = '\0'; +- if (--s >= pa->buf && *s == '\r') +- *s = '\0'; ++ if (s > pa->buf && *(s - 1) == '\r') ++ *(--s) = '\0'; + s = (char *) skip_blank(pa->buf); + } while (*s == '\0' || *s == '#'); + diff --git a/backport-prlimit-fix-optional-arguments-parsing.patch b/backport-prlimit-fix-optional-arguments-parsing.patch new file mode 100644 index 0000000000000000000000000000000000000000..1bd554056e36590a12f60081285fc983e6a2b325 --- /dev/null +++ b/backport-prlimit-fix-optional-arguments-parsing.patch @@ -0,0 +1,31 @@ +From 1ad8db5521ec03d41a058674437f648d15ef8344 Mon Sep 17 00:00:00 2001 +From: Karel Zak +Date: Thu, 18 Mar 2021 10:23:36 +0100 +Subject: [PATCH] prlimit: fix optional arguments parsing + + $ prlimit -f=100:100 + failed to parse FSIZE limit + +Fixes: https://github.com/karelzak/util-linux/issues/1265 +Signed-off-by: Karel Zak +--- + sys-utils/prlimit.c | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/sys-utils/prlimit.c b/sys-utils/prlimit.c +index 6078490..17db3d8 100644 +--- a/sys-utils/prlimit.c ++++ b/sys-utils/prlimit.c +@@ -451,6 +451,9 @@ static int parse_prlim(struct rlimit *lim, char *ops, size_t id) + rlim_t soft, hard; + int found = 0; + ++ if (ops && *ops == '=') ++ ops++; ++ + if (get_range(ops, &soft, &hard, &found)) + errx(EXIT_FAILURE, _("failed to parse %s limit"), + prlimit_desc[id].name); +-- +1.8.3.1 + diff --git a/blkid-fix-ceph_bluestore-dev-by-partlabel-loss-error.patch b/blkid-fix-ceph_bluestore-dev-by-partlabel-loss-error.patch new file mode 100644 index 0000000000000000000000000000000000000000..35bd3d48d38108049dc1aa1b1ba3382a1a7cba13 --- /dev/null +++ b/blkid-fix-ceph_bluestore-dev-by-partlabel-loss-error.patch @@ -0,0 +1,30 @@ +From 4a558f289cd83c993fdb4610aa564f2f4220bca3 Mon Sep 17 00:00:00 2001 +From: zhujun2 +Date: Wed, 14 Jun 2023 15:45:49 +0800 +Subject: [PATCH] blkid: solve a bug that the disk device of the ceph_bluestore + file system, the disk by-partlabel probability loss problem + +Signed-off-by: zhujun2 +--- + libblkid/src/superblocks/xfs.c | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/libblkid/src/superblocks/xfs.c b/libblkid/src/superblocks/xfs.c +index d8c6fb6..3686bd5 100644 +--- a/libblkid/src/superblocks/xfs.c ++++ b/libblkid/src/superblocks/xfs.c +@@ -259,6 +259,11 @@ static int probe_xfs_log(blkid_probe pr, + if (memcmp(&buf[i*512], "XFSB", 4) == 0) + return 1; + ++ if (memcmp(&buf[i*512], "bluestore block device", 22) == 0) { ++ DBG(LOWPROBE, ul_debug("\t device has ceph_bluestore ambivalent")); ++ return 1; ++ } ++ + rhead = (struct xlog_rec_header *)&buf[i*512]; + + if (xlog_valid_rec_header(rhead)) { +-- +2.20.1 + diff --git a/fdisk-fix-quit-dialog-for-non-libreadline-version.patch b/fdisk-fix-quit-dialog-for-non-libreadline-version.patch deleted file mode 100644 index b9e55595d5cb279dd296c6d4ead3506fc8cbc05d..0000000000000000000000000000000000000000 --- a/fdisk-fix-quit-dialog-for-non-libreadline-version.patch +++ /dev/null @@ -1,52 +0,0 @@ -From 40af0db4cdadc50d9ba7ea77d8fa0689bf976f9f Mon Sep 17 00:00:00 2001 -From: Karel Zak -Date: Thu, 5 Sep 2019 12:34:01 +0200 -Subject: [PATCH] fdisk: fix quit dialog for non-libreadline version - -We need to clear stdin errors otherwise it returns EOF forever after -CTRL+D. - -Reported-by: Lukas Czerner -Signed-off-by: Karel Zak ---- - disk-utils/fdisk.c | 4 +++- - 1 file changed, 3 insertions(+), 1 deletion(-) - -diff --git a/disk-utils/fdisk.c b/disk-utils/fdisk.c -index 81334d0..0502fa3 100644 ---- a/disk-utils/fdisk.c -+++ b/disk-utils/fdisk.c -@@ -109,6 +109,7 @@ int get_user_reply(const char *prompt, char *buf, size_t bufsz) - if (is_interactive) - rl_callback_handler_install(prompt, reply_linehandler); - #endif -+ errno = 0; - reply_running = 1; - do { - int rc; -@@ -158,6 +159,7 @@ int get_user_reply(const char *prompt, char *buf, size_t bufsz) - if (!*buf) { - DBG(ASK, ul_debug("cancel by CTRL+D")); - ret = -ECANCELED; -+ clearerr(stdin); - goto done; - } - -@@ -168,13 +170,13 @@ int get_user_reply(const char *prompt, char *buf, size_t bufsz) - if (sz && *(buf + sz - 1) == '\n') - *(buf + sz - 1) = '\0'; - -- DBG(ASK, ul_debug("user's reply: >>>%s<<<", buf)); - done: - #ifdef HAVE_LIBREADLINE - if (is_interactive) - rl_callback_handler_remove(); - #endif - sigaction(SIGINT, &oldact, NULL); -+ DBG(ASK, ul_debug("user's reply: >>>%s<<< [rc=%d]", buf, ret)); - return ret; - } - --- -1.8.3.1 - diff --git a/libmount-parser-fix-memory-leak-on-error-before-end-.patch b/libmount-parser-fix-memory-leak-on-error-before-end-.patch new file mode 100644 index 0000000000000000000000000000000000000000..e50e2340ab3c1f0f76d531ac707d85c35724b35b --- /dev/null +++ b/libmount-parser-fix-memory-leak-on-error-before-end-.patch @@ -0,0 +1,114 @@ +From fe0d12d4f82269096f8d0cffc51ca9590814c284 Mon Sep 17 00:00:00 2001 +From: Karel Zak +Date: Fri, 26 Jun 2020 12:59:32 +0200 +Subject: [PATCH 821/863] libmount: (parser) fix memory leak on error before + end-of-file + +Let's simplify the loop where we add FS to the table. The optimization +for recoverable errors is a fragile overkill. The new code always +allocates and unrefs FS for each loop. + +Addresses: https://github.com/karelzak/util-linux/pull/1068 +Signed-off-by: Karel Zak +--- + libmount/src/fs.c | 2 +- + libmount/src/tab_parse.c | 49 ++++++++++++++++++++++++++---------------------- + 2 files changed, 28 insertions(+), 23 deletions(-) + +diff --git a/libmount/src/fs.c b/libmount/src/fs.c +index bcc8273..52f937a 100644 +--- a/libmount/src/fs.c ++++ b/libmount/src/fs.c +@@ -39,7 +39,7 @@ struct libmnt_fs *mnt_new_fs(void) + + fs->refcount = 1; + INIT_LIST_HEAD(&fs->ents); +- /*DBG(FS, ul_debugobj(fs, "alloc"));*/ ++ DBG(FS, ul_debugobj(fs, "alloc")); + return fs; + } + +diff --git a/libmount/src/tab_parse.c b/libmount/src/tab_parse.c +index 3b52f6b..e3f30c2 100644 +--- a/libmount/src/tab_parse.c ++++ b/libmount/src/tab_parse.c +@@ -703,7 +703,6 @@ static int __table_parse_stream(struct libmnt_table *tb, FILE *f, const char *fi + int rc = -1; + int flags = 0; + pid_t tid = -1; +- struct libmnt_fs *fs = NULL; + struct libmnt_parser pa = { .line = 0 }; + + assert(tb); +@@ -723,19 +722,25 @@ static int __table_parse_stream(struct libmnt_table *tb, FILE *f, const char *fi + if (filename && strcmp(filename, _PATH_PROC_MOUNTS) == 0) + flags = MNT_FS_KERNEL; + +- while (!feof(f)) { +- if (!fs) { +- fs = mnt_new_fs(); +- if (!fs) +- goto err; ++ do { ++ struct libmnt_fs *fs; ++ ++ if (feof(f)) { ++ DBG(TAB, ul_debugobj(tb, "end-of-file")); ++ break; + } ++ fs = mnt_new_fs(); ++ if (!fs) ++ goto err; + ++ /* parse */ + rc = mnt_table_parse_next(&pa, tb, fs); + +- if (!rc && tb->fltrcb && tb->fltrcb(fs, tb->fltrcb_data)) +- rc = 1; /* filtered out by callback... */ ++ if (rc != 0 && tb->fltrcb && tb->fltrcb(fs, tb->fltrcb_data)) ++ rc = 1; /* error filtered out by callback... */ + +- if (!rc) { ++ /* add to the table */ ++ if (rc == 0) { + rc = mnt_table_add_fs(tb, fs); + fs->flags |= flags; + +@@ -746,21 +751,21 @@ static int __table_parse_stream(struct libmnt_table *tb, FILE *f, const char *fi + } + } + +- if (rc) { +- if (rc > 0) { +- mnt_reset_fs(fs); +- assert(fs->refcount == 1); +- continue; /* recoverable error, reuse fs*/ +- } ++ /* remove refernece (or deallocate on error) */ ++ mnt_unref_fs(fs); + +- mnt_unref_fs(fs); +- if (feof(f)) +- break; +- goto err; /* fatal error */ ++ /* recoverable error */ ++ if (rc > 0) { ++ DBG(TAB, ul_debugobj(tb, "recoverable error (continue)")); ++ continue; + } +- mnt_unref_fs(fs); +- fs = NULL; +- } ++ ++ /* fatal errors */ ++ if (rc < 0 && !feof(f)) { ++ DBG(TAB, ul_debugobj(tb, "fatal error")); ++ goto err; ++ } ++ } while (1); + + DBG(TAB, ul_debugobj(tb, "%s: stop parsing (%d entries)", + filename, mnt_table_get_nents(tb))); +-- +1.8.3.1 + diff --git a/lscpu-Add-HiSilicon-aarch64-tsv110-cpupart.patch b/lscpu-Add-HiSilicon-aarch64-tsv110-cpupart.patch deleted file mode 100644 index 6d6efa08f6dfcdb3cdc0bdd039223522f984826c..0000000000000000000000000000000000000000 --- a/lscpu-Add-HiSilicon-aarch64-tsv110-cpupart.patch +++ /dev/null @@ -1,42 +0,0 @@ -From 6f00af5b3c7aadd1322424a84661cfdac83146eb Mon Sep 17 00:00:00 2001 -From: John Garry -Date: Tue, 8 Oct 2019 21:12:21 +0800 -Subject: [PATCH] lscpu: Add HiSilicon aarch64 tsv110 cpupart - -Add an entry for the HiSilicon aarch64 part tsv110. - -Another known alias for this part is TaishanV110, and it can be -found in the Kunpeng920/Hi1620 SoC. - -Signed-off-by: John Garry ---- - sys-utils/lscpu-arm.c | 6 ++++++ - 1 file changed, 6 insertions(+) - -diff --git a/sys-utils/lscpu-arm.c b/sys-utils/lscpu-arm.c -index fd9ab3f..b45cbe3 100644 ---- a/sys-utils/lscpu-arm.c -+++ b/sys-utils/lscpu-arm.c -@@ -170,6 +170,11 @@ static const struct id_part intel_part[] = { - { -1, "unknown" }, - }; - -+static const struct id_part hisi_part[] = { -+ { 0xd01, "tsv110" }, -+ { -1, "unknown" }, -+}; -+ - static const struct id_part unknown_part[] = { - { -1, "unknown" }, - }; -@@ -185,6 +190,7 @@ static const struct hw_impl hw_implementer[] = { - { 0x42, brcm_part, "Broadcom" }, - { 0x43, cavium_part, "Cavium" }, - { 0x44, dec_part, "DEC" }, -+ { 0x48, hisi_part, "HiSilicon" }, - { 0x4e, nvidia_part, "Nvidia" }, - { 0x50, apm_part, "APM" }, - { 0x51, qcom_part, "Qualcomm" }, --- -1.8.3.1 - diff --git a/lscpu-use-official-name-for-HiSilicon-tsv110.patch b/lscpu-use-official-name-for-HiSilicon-tsv110.patch deleted file mode 100644 index e32253a2ccb07ab4932a3fb2fd48d0866e9ba550..0000000000000000000000000000000000000000 --- a/lscpu-use-official-name-for-HiSilicon-tsv110.patch +++ /dev/null @@ -1,36 +0,0 @@ -From 8243036cae35c1be6992b0ef722d68585589d7d7 Mon Sep 17 00:00:00 2001 -From: Karel Zak -Date: Wed, 4 Mar 2020 12:54:24 +0100 -Subject: [PATCH] lscpu: use official name for HiSilicon tsv110 - -Addresses: https://github.com/karelzak/util-linux/issues/969 -Signed-off-by: Karel Zak ---- - sys-utils/lscpu-arm.c | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - -diff --git a/sys-utils/lscpu-arm.c b/sys-utils/lscpu-arm.c -index b45cbe3..ef9d1ff 100644 ---- a/sys-utils/lscpu-arm.c -+++ b/sys-utils/lscpu-arm.c -@@ -171,7 +171,7 @@ static const struct id_part intel_part[] = { - }; - - static const struct id_part hisi_part[] = { -- { 0xd01, "tsv110" }, -+ { 0xd01, "Kunpeng-920" }, /* aka tsv110 */ - { -1, "unknown" }, - }; - -@@ -190,7 +190,7 @@ static const struct hw_impl hw_implementer[] = { - { 0x42, brcm_part, "Broadcom" }, - { 0x43, cavium_part, "Cavium" }, - { 0x44, dec_part, "DEC" }, -- { 0x48, hisi_part, "HiSilicon" }, -+ { 0x48, hisi_part, "HiSilicon" }, - { 0x4e, nvidia_part, "Nvidia" }, - { 0x50, apm_part, "APM" }, - { 0x51, qcom_part, "Qualcomm" }, --- -1.8.3.1 - diff --git a/modify-rescuemode-chinese-error.patch b/modify-rescuemode-chinese-error.patch new file mode 100644 index 0000000000000000000000000000000000000000..62c7b4d14a615dd16085beaa054c8b207564bf5e --- /dev/null +++ b/modify-rescuemode-chinese-error.patch @@ -0,0 +1,56 @@ +From 5b81afefaba928dfb2f6686ed90e4512fff19357 Mon Sep 17 00:00:00 2001 +From: ut001695 +Date: Fri, 6 Nov 2020 16:28:05 +0800 +Subject: [PATCH] 1 + +--- + po/util-linux.pot | 8 ++++---- + po/zh_CN.po | 12 ++++++------ + 2 files changed, 10 insertions(+), 10 deletions(-) + +diff --git a/po/util-linux.pot b/po/util-linux.pot +index fe84f6e..ebbc162 100644 +--- a/po/util-linux.pot ++++ b/po/util-linux.pot +@@ -7622,10 +7622,10 @@ msgstr "" + + #: login-utils/login.c:801 login-utils/sulogin.c:1013 + #, c-format +-msgid "" +-"Login incorrect\n" +-"\n" +-msgstr "" ++#msgid "" ++#"Login incorrect\n" ++#"\n" ++#msgstr "" + + #: login-utils/login.c:816 + #, c-format +diff --git a/po/zh_CN.po b/po/zh_CN.po +index 9da9f78..2f6e31b 100644 +--- a/po/zh_CN.po ++++ b/po/zh_CN.po +@@ -7624,12 +7624,12 @@ msgstr "FAILED LOGIN %u FROM %s FOR %s, %s" + + #: login-utils/login.c:801 login-utils/sulogin.c:1013 + #, c-format +-msgid "" +-"Login incorrect\n" +-"\n" +-msgstr "" +-"登录不正确\n" +-"\n" ++#msgid "" ++#"Login incorrect\n" ++#"\n" ++#msgstr "" ++#"登录不正确\n" ++#"\n" + + #: login-utils/login.c:816 + #, c-format +-- +2.23.0 + + diff --git a/tests-Fix-mountpoint-test-failure-in-build-chroots.patch b/tests-Fix-mountpoint-test-failure-in-build-chroots.patch new file mode 100644 index 0000000000000000000000000000000000000000..774eef9f9267d1f465745baf5b327bd9f219d8a3 --- /dev/null +++ b/tests-Fix-mountpoint-test-failure-in-build-chroots.patch @@ -0,0 +1,74 @@ +From 3e9395811708b5ebcf2c5079ff0cb6d18694a3cc Mon Sep 17 00:00:00 2001 +From: Mark Hindley +Date: Mon, 22 Jun 2020 23:52:09 +0000 +Subject: [PATCH 819/863] tests: Fix mountpoint test failure in build chroots. + +The test assumed that / was a mountpoint. This is not always the case, for +example in pbuilder/cowbuilder chroots. So use / if findmnt verifies it is a +mountpoint, otherwise use the first mountpoint found. Skip the test if no +mountpoints are found. + +Signed-off-by: Mark Hindley +--- + tests/expected/misc/mountpoint-default | 2 +- + tests/expected/misc/mountpoint-nofollow | 2 +- + tests/ts/misc/mountpoint | 15 +++++++++++---- + 3 files changed, 13 insertions(+), 6 deletions(-) + +diff --git a/tests/expected/misc/mountpoint-default b/tests/expected/misc/mountpoint-default +index 9a7ac6a..ca75055 100644 +--- a/tests/expected/misc/mountpoint-default ++++ b/tests/expected/misc/mountpoint-default +@@ -1,2 +1,2 @@ +-./symlink-to-root is a mountpoint ++./symlink-to-mountpoint is a mountpoint + 0 +diff --git a/tests/expected/misc/mountpoint-nofollow b/tests/expected/misc/mountpoint-nofollow +index 1ba1749..03d2b5d 100644 +--- a/tests/expected/misc/mountpoint-nofollow ++++ b/tests/expected/misc/mountpoint-nofollow +@@ -1,2 +1,2 @@ +-./symlink-to-root is not a mountpoint ++./symlink-to-mountpoint is not a mountpoint + 1 +diff --git a/tests/ts/misc/mountpoint b/tests/ts/misc/mountpoint +index 1b391c3..e52ccb2 100755 +--- a/tests/ts/misc/mountpoint ++++ b/tests/ts/misc/mountpoint +@@ -7,16 +7,23 @@ TS_DESC="mountpoint" + ts_init "$*" + + ts_check_test_command "$TS_CMD_MOUNTPOINT" ++ts_check_test_command "$TS_CMD_FINDMNT" + +-ln -s / ./symlink-to-root ++# / is not always a mountpoint (chroots etc.), so check if it is and otherwise ++# fallback to the first available mountpoint. ++FIRST_MOUNTPOINT=$($TS_CMD_FINDMNT -no TARGET / || $TS_CMD_FINDMNT -fno TARGET) ++ ++[ -z "$FIRST_MOUNTPOINT" ] && ts_skip "no mountpoint found for symlink tests" ++ ++ln -s $FIRST_MOUNTPOINT ./symlink-to-mountpoint + + ts_init_subtest "default" +-$TS_CMD_MOUNTPOINT ./symlink-to-root >> $TS_OUTPUT 2>> $TS_ERRLOG ++$TS_CMD_MOUNTPOINT ./symlink-to-mountpoint >> $TS_OUTPUT 2>> $TS_ERRLOG + echo $? >> $TS_OUTPUT 2>> $TS_ERRLOG + ts_finalize_subtest + + ts_init_subtest "nofollow" +-$TS_CMD_MOUNTPOINT --nofollow ./symlink-to-root >> $TS_OUTPUT 2>> $TS_ERRLOG ++$TS_CMD_MOUNTPOINT --nofollow ./symlink-to-mountpoint >> $TS_OUTPUT 2>> $TS_ERRLOG + echo $? >> $TS_OUTPUT 2>> $TS_ERRLOG + ts_finalize_subtest + +@@ -25,5 +32,5 @@ $TS_CMD_MOUNTPOINT --devno --nofollow / >> $TS_OUTPUT 2>> $TS_ERRLOG + echo $? >> $TS_OUTPUT 2>> $TS_ERRLOG + ts_finalize_subtest + +-rm -f ./symlink-to-root ++rm -f ./symlink-to-mountpoint + ts_finalize +-- +1.8.3.1 + diff --git a/util-linux-2.34.tar.xz b/util-linux-2.35.2.tar.xz similarity index 40% rename from util-linux-2.34.tar.xz rename to util-linux-2.35.2.tar.xz index 539be36ee5b7dfc5c0c05f7de2378901aaa3f4d2..30eb8f31ca23b8c98e638a961f249d53e377c123 100644 Binary files a/util-linux-2.34.tar.xz and b/util-linux-2.35.2.tar.xz differ diff --git a/util-linux-login.pamd b/util-linux-login.pamd index 98e30d7fb6fb78860361969a7c89cfcdfb709374..517b79811af801ee1b21b3a006d2624da0cf0866 100644 --- a/util-linux-login.pamd +++ b/util-linux-login.pamd @@ -7,7 +7,6 @@ password include system-auth # pam_selinux.so close should be the first session rule session required pam_selinux.so close session required pam_loginuid.so -session optional pam_console.so # pam_selinux.so open should only be followed by sessions to be executed in the user context session required pam_selinux.so open session required pam_namespace.so diff --git a/util-linux.spec b/util-linux.spec index e38723ecef2b3a1563ca1f7bf44f4580f9a5878b..44c6032c0c8a07cfa344060c5a8b605f00a12ef8 100644 --- a/util-linux.spec +++ b/util-linux.spec @@ -1,8 +1,8 @@ %define compldir %{_datadir}/bash-completion/completions/ Name: util-linux -Version: 2.34 -Release: 8 +Version: 2.35.2 +Release: 13 Summary: A random collection of Linux utilities License: GPLv2 and GPLv2+ and LGPLv2+ and BSD with advertising and Public Domain URL: https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git @@ -25,22 +25,47 @@ Requires: pam >= 1.1.3-7, /etc/pam.d/system-auth audit-libs >= 1.0.6 Requires: libblkid = %{version}-%{release} libmount = %{version}-%{release} libsmartcols = %{version}-%{release} Requires: libfdisk = %{version}-%{release} libuuid = %{version}-%{release} -Conflicts: initscripts < 9.79-4 bash-completion < 1:2.1-1 coreutils < 8.20 sysvinit-tools < 2.88-14 +Conflicts: initscripts < 9.79-4 bash-completion < 1:2.1-1 coreutils < 8.20 Conflicts: e2fsprogs < 1.41.8-5 filesystem < 3 Provides: eject = 2.1.6 rfkill = 0.5 -Provides: util-linux-ng = %{version}-%{release} +Provides: util-linux-ng = %{version}-%{release} hardlink = 1:1.3-9 Provides: /bin/dmesg /bin/kill /bin/more /bin/mount /bin/umount /sbin/blkid Provides: /sbin/blockdev /sbin/findfs /sbin/fsck /sbin/nologin -Obsoletes: eject <= 2.1.5 rfkill <= 0.5 util-linux-ng < 2.19 - -Patch0000: 2.28-login-lastlog-create.patch -Patch0001: fdisk-fix-quit-dialog-for-non-libreadline-version.patch -Patch0002: libmount-move-already-mounted-code-to-separate-funct.patch -Patch0003: libmount-try-read-only-mount-on-write-protected-supe.patch -Patch0004: lscpu-Add-HiSilicon-aarch64-tsv110-cpupart.patch -Patch0005: lscpu-use-official-name-for-HiSilicon-tsv110.patch - +Obsoletes: eject <= 2.1.5 rfkill <= 0.5 util-linux-ng < 2.19 sysvinit-tools < 0:2.89 hardlink <= 1:1.3-9 + +Patch0: 2.28-login-lastlog-create.patch +Patch1: libmount-move-already-mounted-code-to-separate-funct.patch +Patch2: libmount-try-read-only-mount-on-write-protected-supe.patch +Patch3: libmount-parser-fix-memory-leak-on-error-before-end-.patch +Patch4: tests-Fix-mountpoint-test-failure-in-build-chroots.patch + +Patch5: backport-libfdisk-add-partition-type-aliases-and-shortcuts.patch +Patch6: backport-fdisk-add-support-for-parttype-aliases.patch +Patch7: backport-lib-strutils-fix-floating-point-exception.patch +Patch8: backport-libfdisk-script-make-sure-label-is-specified.patch +Patch9: backport-libfdisk-script-don-t-use-sector-size-if-not-specifi.patch +Patch10: backport-libfdisk-fix-typo-from-255f5f4c770ebd46a38b58975bd33.patch +Patch11: backport-libfdisk-make-fdisk_partname-more-robust.patch +Patch12: backport-libfdisk-another-parse_line-nameval-cleanup.patch +Patch13: backport-libfdisk-script-fix-possible-memory-leaks.patch +Patch14: backport-libfdisk-script-fix-possible-partno-overflow.patch +Patch15: backport-libmount-fix-tab-parser-for-badly-terminated-lines.patch +Patch16: backport-clang-tidy-fix-wrong-cmp-usage.patch +Patch17: backport-libblkid-improve-debug-for-proc-partitions.patch +Patch18: backport-libblkid-use-sys-to-read-all-block-devices.patch +Patch19: backpaort-fix-rounding-in-size_to_human_string.patch +Patch20: backpaort-fix-uint64_t-overflow.patch +Patch21: backpaort-update-fdisk-outputs-due-to-sizes-rounding-change.patch +Patch6000: backport-CVE-2021-37600.patch +Patch6001: backport-add-ul_strtou64.patch +Patch6002: backport-CVE-2021-3995.patch +Patch6003: backport-CVE-2021-3996.patch +Patch6004: backport-prlimit-fix-optional-arguments-parsing.patch +Patch6005: blkid-fix-ceph_bluestore-disk-label-loss-error.patch + +Patch9000: Add-check-to-resolve-uname26-version-test-failed.patch +Patch9001: modify-rescuemode-chinese-error.patch %description The util-linux package contains a random collection of files that implements some low-level basic linux utilities. @@ -134,6 +159,8 @@ development of %{name}. Summary: Help package for ${name} BuildArch: noarch Requires: %{name} = %{version}-%{release} +Obsoletes: hardlink-help <= 1:1.3-9 +Provides: hardlink-help = 1:1.3-9 %description help This package contains some doc and man help files for %{name}. @@ -155,6 +182,7 @@ unset LINGUAS || : --enable-usrdir-path \ --enable-write \ --enable-raw \ + --enable-hardlink \ --with-python=2 \ --with-systemd \ --with-udev \ @@ -289,6 +317,7 @@ fi %attr(4755,root,root) %{_bindir}/su %attr(755,root,root) %{_bindir}/login %attr(2755,root,tty) %{_bindir}/write +%attr(2555,root,tty) %{_bindir}/wall %ghost %attr(0644,root,root) %verify(not md5 size mtime) /var/log/lastlog %ghost %verify(not md5 size mtime) %config(noreplace,missingok) /etc/mtab %{_unitdir}/fstrim.* @@ -296,7 +325,7 @@ fi %{_bindir}/{flock,getopt,hexdump,ionice,ipcmk,ipcrm,ipcs,isosize,kill,last,lastb,logger,hardlink} %{_bindir}/{look,lsblk,lscpu,lsipc,lslocks,lslogins,lsmem,lsns,mcookie,mesg,more,mountpoint} %{_bindir}/{namei,nsenter,prlimit,raw,rename,renice,rev,script,scriptreplay,setarch,setpriv} -%{_bindir}/{setsid,setterm,taskset,ul,unshare,utmpdump,uuidgen,uuidparse,wall,wdctl,whereis} +%{_bindir}/{setsid,setterm,taskset,ul,unshare,utmpdump,uuidgen,uuidparse,wdctl,whereis,scriptlive} %{_sbindir}/{addpart,agetty,blkdiscard,blkid,blkzone,blockdev,chcpu,ctrlaltdel,delpart,fdisk} %{_sbindir}/{findfs,fsck,fsck.cramfs,fsck.minix,fsfreeze,fstrim,ldattach,losetup,mkfs,mkfs.cramfs} %{_sbindir}/{mkfs.minix,mkswap,nologin,partx,pivot_root,readprofile,resizepart,rfkill,rtcwake} @@ -312,7 +341,7 @@ fi %{compldir}/{resizepart,rev,rfkill,rtcwake,runuser,script,scriptreplay,setarch} %{compldir}/{setpriv,setsid,setterm,su,swaplabel,swapoff,swapon,taskset,ul,unshare} %{compldir}/{utmpdump,uuidgen,uuidparse,wall,wdctl,whereis,wipefs,write,zramctl} -%{compldir}/{fdformat,hwclock,cfdisk,sfdisk} +%{compldir}/{fdformat,hwclock,cfdisk,sfdisk,scriptlive} %files -n libfdisk %license Documentation/licenses/COPYING.LGPL-2.1* libfdisk/COPYING @@ -364,13 +393,12 @@ fi %exclude %{_datadir}/doc/util-linux/getopt/* %doc README NEWS Documentation/deprecated.txt %doc %attr(0644,-,-) misc-utils/getopt-*.{bash,tcsh} -%exclude %{_mandir}/man1/hardlink.1* %{_mandir}/man1/{chfn.1*,chsh.1*,cal.1*,chrt.1*,col.1*,colcrt.1*,colrm.1*,column.1*,dmesg.1*,eject.1*} %{_mandir}/man1/{fallocate.1*,fincore.1*,flock.1*,getopt.1*,hexdump.1*,ionice.1*,ipcmk.1*,ipcrm.1*,ipcs.1*} %{_mandir}/man1/{kill.1*,last.1*,lastb.1*,logger.1*,login.1*,look.1*,lscpu.1*,lsipc.1*,lslogins.1*,lsmem.1*} %{_mandir}/man1/{mcookie.1*,mesg.1*,more.1*,mountpoint.1*,namei.1*,nsenter.1*,prlimit.1*,rename.1*,renice.1*} %{_mandir}/man1/{rev.1*,runuser.1*,script.1*,scriptreplay.1*,setpriv.1*,setsid.1*,setterm.1*,su.1*,taskset.1*} -%{_mandir}/man1/{ul.1*,unshare.1*,utmpdump.1.gz,uuidgen.1*,uuidparse.1*,wall.1*,whereis.1*,write.1*,choom.1*} +%{_mandir}/man1/{ul.1*,unshare.1*,utmpdump.1.gz,uuidgen.1*,uuidparse.1*,wall.1*,whereis.1*,write.1*,choom.1*,scriptlive*,hardlink.1*} %{_mandir}/man3/{libblkid.3*,uuid.3*,uuid_clear.3*,uuid_compare.3*,uuid_copy.3*,uuid_generate.3*,uuid_generate_random.3*} %{_mandir}/man3/{uuid_generate_time_safe.3*,uuid_is_null.3*,uuid_parse.3*,uuid_time.3*,uuid_unparse.3*,uuid_generate_time.3*} %{_mandir}/man5/{fstab.5*,terminal-colors.d.5*,adjtime_config.5.*} @@ -383,6 +411,83 @@ fi %{_mandir}/man8/{swapoff.8*,swapon.8*,switch_root.8*,umount.8*,wdctl.8.gz,wipefs.8*,zramctl.8*} %changelog +* Wed Jun 14 2023 zhujun - 2.35.2-13 +- Type:bugfix +- ID:NA +- SUG:NA +- DESC:solve a bug that disk device of ceph_bluestore file system,the disk by-partlabel probability loss problem + +* Wed Sep 7 2022 Xiaole He - 2.35.2-12 +- Type:bugfix +- ID:NA +- SUG:NA +- DESC:add hardlink manpage + +* Wed Mar 16 2022 shangyibin - 2.35.2-11 +- Type:bugfix +- ID:NA +- SUG:NA +- DESC:prlimit fix optional arguments parsing + +* Tue Feb 15 2022 shangyibin - 2.35.2-10 +- Type:CVE +- ID:CVE-2021-3995 CVE-2021-3996 +- SUG:NA +- DESC:fix CVE-2021-3995 CVE-2021-3996 + +* Fri Aug 20 2021 zhangke - 2.35.2-9 +- Type:enhancement +- Id:NA +- SUG:NA +- DESC:modify rescuemode chinese error + +* Tue Aug 10 2021 shixuantong - 2.35.2-8 +- Type:CVE +- ID:CVE-2021-37600 +- SUG:NA +- DESC:fix CVE-2021-37600 + +* Wed Jul 28 2021 shangyibin - 2.35.2-7 +- Type:bugfix +- ID:NA +- SUG:NA +- DESC:fix rounding in size_to_human_string() + +* Thu May 06 2021 tianwei - 2.35.2-6 +- Type:enhancement +- ID:NA +- SUG:NA +- DESC:add command hardlink + +* Thu Mar 18 2021 wangchen - 2.35.2-5 +- Use /sys to read all block devices + +* Mon Mar 1 2021 yangzhuangzhuang - 2.35.2-4 +- Fix memleak in fdisk_script_read_file + Fix heap-buffer-overflow in fdisk_partname + Fix integer overflow in partno_from_devname + +* Mon Jan 18 2021 Liquor - 2.35.2-3 +- Remove pam_console dependency + +* Thu Dec 17 2020 Liquor - 2.35.2-2 +- Add check to resolve uname26-version test failed + +* Wed Jul 29 2020 fangxiuning - 2.35.2-1 +- Update version to 2.35.2 + +* Tue Jul 28 2020 shenyangyang - 2.35.1-3 +- libmount parser fix memory leak on error before end + +* Wed Jul 1 2020 liuchengaung - 2.35.1-2 +- quality enhancement synchronization github patch + +* Mon May 11 2020 openEuler Buildteam - 2.35.1-1 +- Type:requirement +- ID:NA +- SUG:NA +- DESC:update to 2.35.1 + * Sun Mar 22 2020 openEuler Buildteam - 2.34-8 - Type:enhancement - ID:NA diff --git a/write-fix-potential-string-overflow.patch b/write-fix-potential-string-overflow.patch new file mode 100644 index 0000000000000000000000000000000000000000..1eb12010c2350d0201ed4d034ce33ad77c0eab7a --- /dev/null +++ b/write-fix-potential-string-overflow.patch @@ -0,0 +1,41 @@ +From cdf84bf65804873708b2b76551d64116123ac128 Mon Sep 17 00:00:00 2001 +From: Sami Kerola +Date: Sat, 8 Feb 2020 21:12:14 +0000 +Subject: [PATCH 038/389] write: fix potential string overflow +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Noticed when compiled with gcc verion 9.2.1 20200130. + +term-utils/write.c:182:7: warning: ‘strcmp’ argument 1 declared attribute + ‘nonstring’ [-Wstringop-overflow=] + 182 | if (strcmp(u->ut_line, ctl->src_tty_name) == 0) { + | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +In file included from /usr/include/utmpx.h:31, + from term-utils/write.c:60: +/usr/include/bits/utmpx.h:59:8: note: argument ‘ut_line’ declared here + 59 | char ut_line[__UT_LINESIZE] + | ^~~~~~~ + +Signed-off-by: Sami Kerola +--- + term-utils/write.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/term-utils/write.c b/term-utils/write.c +index 3436fbd..90eb18c 100644 +--- a/term-utils/write.c ++++ b/term-utils/write.c +@@ -179,7 +179,7 @@ static void search_utmp(struct write_control *ctl) + if (ctl->src_uid && !tty_writeable) + /* skip ttys with msgs off */ + continue; +- if (strcmp(u->ut_line, ctl->src_tty_name) == 0) { ++ if (memcmp(u->ut_line, ctl->src_tty_name, strlen(ctl->src_tty_name) + 1) == 0) { + user_is_me = 1; + /* don't write to yourself */ + continue; +-- +1.8.3.1 +