libfdisk: fix fdisk_reread_changes() for extended partitions.

This commit is contained in:
roy 2024-09-20 15:15:35 +08:00
parent 1d66741fbd
commit 27ae2c6425
3 changed files with 50 additions and 42 deletions

View File

@ -0,0 +1,40 @@
commit b0098c1ebd3bd068edaa38be67ac48b6c1218e98
Author: Karel Zak <kzak@redhat.com>
Date: Thu Aug 6 11:32:33 2020 +0200
libfdisk: fix fdisk_reread_changes() for extended partitions
Linux kernel assumes only 1KiB extended partition to avoid overlapping
with nested logical partitions. We need to follow this rule for
BLKPG_ADD_PARTITION.
Addresses: https://github.com/karelzak/util-linux/issues/1112
Signed-off-by: Karel Zak <kzak@redhat.com>
diff --git a/libfdisk/src/context.c b/libfdisk/src/context.c
index 363db30f4..327e03b42 100644
--- a/libfdisk/src/context.c
+++ b/libfdisk/src/context.c
@@ -939,10 +939,21 @@ int fdisk_reread_changes(struct fdisk_context *cxt, struct fdisk_table *org)
}
}
for (i = 0; i < nadds; i++) {
+ uint64_t sz;
+
pa = add[i];
+ sz = pa->size * ssf;
+
DBG(PART, ul_debugobj(pa, "#%zu calling BLKPG_ADD_PARTITION", pa->partno));
+
+ if (fdisk_is_label(cxt, DOS) && fdisk_partition_is_container(pa))
+ /* Let's follow the Linux kernel and reduce
+ * DOS extended partition to 1 or 2 sectors.
+ */
+ sz = min(sz, (uint64_t) 2);
+
if (partx_add_partition(cxt->dev_fd, pa->partno + 1,
- pa->start * ssf, pa->size * ssf) != 0) {
+ pa->start * ssf, sz) != 0) {
fdisk_warn(cxt, _("Failed to add partition %zu to system"), pa->partno + 1);
err++;
}

View File

@ -2,7 +2,7 @@
Name: util-linux
Version: 2.35.2
Release: 18
Release: 19
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
@ -90,12 +90,14 @@ Patch6010: backport-CVE-2024-28085.patch
Patch6011: backport-tests-fix-misc-setarch-run-in-a-docker-environment.patch
Patch6012: backport-include-c.h-add-helpers-for-unaligned-structure-acce.patch
Patch6013: backport-libblkid-drbd-reduce-false-positive.patch
Patch6014: backport-libfdisk-fix-fdisk_reread_changes-for-extended-partitions.patch
Patch9000: Add-check-to-resolve-uname26-version-test-failed.patch
Patch9001: modify-rescuemode-chinese-error.patch
Patch9002: huawei-bios-model-name.patch
Patch9003: backport-uuidd-fix-open-lock-state-issue.patch
%description
The util-linux package contains a random collection of files that
implements some low-level basic linux utilities.
@ -441,6 +443,13 @@ fi
%{_mandir}/man8/{swapoff.8*,swapon.8*,switch_root.8*,umount.8*,wdctl.8.gz,wipefs.8*,zramctl.8*}
%changelog
* Fri Sep 20 2024 Yu Peng <yupeng@kylinos.cn> - 2.35.2-19
- Type:bugfix
- CVE:NA
- SUG:NA
- DESC:sync community patches
backport-libfdisk-fix-fdisk_reread_changes-for-extended-partitions.patch
* Mon Aug 5 2024 liyuzhe <liyuzhe@cqsoftware.com.cn> - 2.35.2-18
- Fixed incorrect macro usage in summary fields of devel and help subpackages

View File

@ -1,41 +0,0 @@
From cdf84bf65804873708b2b76551d64116123ac128 Mon Sep 17 00:00:00 2001
From: Sami Kerola <kerolasa@iki.fi>
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 <kerolasa@iki.fi>
---
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