- Add missing patches from Wang Dong

- fix crash due to improper partition number (dongdwdw)
- fix wrong error label jump in mkpart (dongdwdw)
- clean the disk information when commands fail (dongdwdw)
- Remove PED_ASSERT from ped_partition_set_name (bcl)
- Added support for Windows recovery partition (Hans-Joachim.Baader)
This commit is contained in:
Brian C. Lane 2019-01-31 11:35:16 -08:00
parent 901c30f0f2
commit 21f562c24e
6 changed files with 463 additions and 1 deletions

View File

@ -0,0 +1,94 @@
From 149f009c3b4ab6bac8059b48142a1c3f698c8e53 Mon Sep 17 00:00:00 2001
From: Wang Dong <dongdwdw@linux.vnet.ibm.com>
Date: Fri, 23 Dec 2016 06:53:36 +0100
Subject: [PATCH 104/106] parted: fix crash due to improper partition number
input
When the user makes a new partition, if parted fails to add the
partition to disk, it jumps to wrong error label. In this
situation, this new partition actually is not a node in disk
data structure. But in the wrong error label, it pretends this
is a node and removes it as a list node, leading to other
partition in this disk deleted. This might lead to a memory leak.
Because if there are other partitions, it just removes them from
list without releasing the resource. And this also leads to different
disk information between memory and device. This is confusing.
But when the new partition is added to disk successfully and if
any operations followed fail, this partition should be removed from
disk and destroyed.
Signed-off-by: Wang Dong <dongdwdw@linux.vnet.ibm.com>
Signed-off-by: Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
---
parted/ui.c | 26 ++++++++++++++++++++++----
1 file changed, 22 insertions(+), 4 deletions(-)
diff --git a/parted/ui.c b/parted/ui.c
index 505b8ac..5d76c20 100644
--- a/parted/ui.c
+++ b/parted/ui.c
@@ -29,6 +29,8 @@
#include <unistd.h>
#include <setjmp.h>
#include <assert.h>
+#include <limits.h>
+#include <errno.h>
#include "command.h"
#include "strlist.h"
@@ -909,16 +911,30 @@ command_line_get_integer (const char* prompt, int* value)
{
char def_str [10];
char* input;
- int valid;
+ long ret;
snprintf (def_str, 10, "%d", *value);
input = command_line_get_word (prompt, *value ? def_str : NULL,
NULL, 1);
if (!input)
return 0;
- valid = sscanf (input, "%d", value);
+
+ errno = 0;
+ ret = strtol (input, (char**) NULL, 10);
+ if (errno)
+ goto error;
+
+ if ((ret > INT_MAX) || (ret < INT_MIN))
+ goto error;
+ else
+ *value = (int) ret;
+
free (input);
- return valid;
+ return 1;
+
+error:
+ free (input);
+ return 0;
}
int
@@ -1029,6 +1045,7 @@ command_line_get_partition (const char* prompt, PedDisk* disk,
PedPartition** value)
{
PedPartition* part;
+ int ret;
/* Flawed logic, doesn't seem to work?!
check = ped_disk_next_partition (disk, part);
@@ -1045,7 +1062,8 @@ command_line_get_partition (const char* prompt, PedDisk* disk,
*/
int num = (*value) ? (*value)->num : 0;
- if (!command_line_get_integer (prompt, &num)) {
+ ret = command_line_get_integer (prompt, &num);
+ if ((!ret) || (num < 0)) {
ped_exception_throw (PED_EXCEPTION_ERROR,
PED_EXCEPTION_CANCEL,
_("Expecting a partition number."));
--
2.20.1

View File

@ -0,0 +1,66 @@
From af150f6764a08eae4b4cf448c392259c067a1523 Mon Sep 17 00:00:00 2001
From: Wang Dong <dongdwdw@linux.vnet.ibm.com>
Date: Fri, 23 Dec 2016 06:53:37 +0100
Subject: [PATCH 105/106] parted: fix wrong error label jump in mkpart
When the user makes a new partition, if parted fails to add the
partition to disk, it jumps to wrong error label. In this
situation, this new partition actually is not a node in disk
data structure. But in the wrong error label, it pretends this
is a node and removes it as a list node, leading to other
partition in this disk deleted. This might lead to a memory leak.
Because if there are other partitions, it just removes them from
list without releasing the resource. And this also leads to different
disk information between memory and device. This is confusing.
But when the new partition is added to disk successfully and if
any operations followed fail, this partition should be removed from
disk and destroyed.
Signed-off-by: Wang Dong <dongdwdw@linux.vnet.ibm.com>
Signed-off-by: Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
---
parted/parted.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/parted/parted.c b/parted/parted.c
index a72a4eb..4bb7911 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -742,7 +742,7 @@ do_mkpart (PedDevice** dev, PedDisk** diskp)
ped_constraint_destroy (constraint_any);
if (!added_ok)
- goto error_remove_part;
+ goto error_destroy_simple_constraints;
if (!ped_geometry_test_sector_inside(range_start, part->geom.start) ||
!ped_geometry_test_sector_inside(range_end, part->geom.end)) {
@@ -817,12 +817,12 @@ do_mkpart (PedDevice** dev, PedDisk** diskp)
free (part_name); /* avoid double-free upon failure */
part_name = NULL;
if (!ped_partition_set_system (part, fs_type))
- goto error;
+ goto error_remove_part;
if (ped_partition_is_flag_available (part, PED_PARTITION_LBA))
ped_partition_set_flag (part, PED_PARTITION_LBA, 1);
if (!ped_disk_commit (disk))
- goto error;
+ goto error_remove_part;
/* clean up */
if (range_start != NULL)
@@ -845,7 +845,8 @@ error_remove_part:
error_destroy_simple_constraints:
ped_partition_destroy (part);
error:
- free (part_name);
+ if (part_name)
+ free (part_name);
if (range_start != NULL)
ped_geometry_destroy (range_start);
if (range_end != NULL)
--
2.20.1

View File

@ -0,0 +1,86 @@
From 5a61f15b7003cba73e6517ac22204bafd9a3cb8e Mon Sep 17 00:00:00 2001
From: Wang Dong <dongdwdw@linux.vnet.ibm.com>
Date: Fri, 23 Dec 2016 06:53:38 +0100
Subject: [PATCH 106/106] clean the disk information when commands fail in
interactive mode.
parted always reads disk information to memory before any
operations. The disk that user operates is actually
a copy of real one in memory. When the information in memory
is changed, it will commit the memory to device to update the
disk information.
Once the disk information is read, parted will never re-read it
again unless another device is loaded or the device is re-read.
Above work has been done in commit 7eac058 (parted: don't reload
partition table on every command)
Each command of parted always commits the memory when it succeeds.
Then the disk information on device and in memory are the same.
But when it fails, they might be different. User will be confused
by this, and sometimes get undesired result with the contaminated
memory. This memory should be cleaned if some command fails.
Then the command followed will re-read the disk.
Signed-off-by: Wang Dong <dongdwdw@linux.vnet.ibm.com>
Signed-off-by: Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
---
parted/parted.c | 14 ++++++++++----
parted/ui.c | 8 +++++++-
2 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/parted/parted.c b/parted/parted.c
index 4bb7911..59ad59e 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -1390,8 +1390,12 @@ _rescue_add_partition (PedPartition* part)
default: break;
}
- ped_partition_set_system (part, fs_type);
- ped_disk_commit (part->disk);
+ if (!ped_partition_set_system (part, fs_type))
+ return 0;
+
+ if (!ped_disk_commit (part->disk))
+ return 0;
+
return 1;
}
@@ -1601,8 +1605,10 @@ do_rm (PedDevice** dev, PedDisk** diskp)
if (!_partition_warn_busy (part))
goto error;
- ped_disk_delete_partition (*diskp, part);
- ped_disk_commit (*diskp);
+ if (!ped_disk_delete_partition (*diskp, part))
+ goto error;
+ if (!ped_disk_commit (*diskp))
+ goto error;
if ((*dev)->type != PED_DEVICE_FILE)
disk_is_modified = 1;
diff --git a/parted/ui.c b/parted/ui.c
index 5d76c20..af0539c 100644
--- a/parted/ui.c
+++ b/parted/ui.c
@@ -1612,8 +1612,14 @@ interactive_mode (PedDevice** dev, PedDisk** disk, Command* cmd_list[])
cmd = command_get (commands, word);
free (word);
if (cmd) {
- if (!command_run (cmd, dev, disk))
+ if (!command_run (cmd, dev, disk)) {
command_line_flush ();
+
+ if (*disk) {
+ ped_disk_destroy (*disk);
+ *disk = 0;
+ }
+ }
} else
print_commands_help ();
}
--
2.20.1

View File

@ -0,0 +1,32 @@
From 0601c8ea6de92017ee8c6293db102029e309b166 Mon Sep 17 00:00:00 2001
From: "Brian C. Lane" <bcl@redhat.com>
Date: Thu, 31 Jan 2019 08:59:55 -0800
Subject: [PATCH] parted: Remove PED_ASSERT from ped_partition_set_name
Asserts should only check logic, not wrap functions with side-effects.
When compiled with --disable-debug this causes the name field of mkpart
to be ignored.
---
parted/parted.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/parted/parted.c b/parted/parted.c
index 35432c6..c0600ea 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -814,9 +814,11 @@ do_mkpart (PedDevice** dev, PedDisk** diskp)
/* set minor attributes */
if (part_name)
- PED_ASSERT (ped_partition_set_name (part, part_name));
+ if (!ped_partition_set_name (part, part_name))
+ goto error_remove_part;
free (part_name); /* avoid double-free upon failure */
part_name = NULL;
+
if (!ped_partition_set_system (part, fs_type))
goto error_remove_part;
if (ped_partition_is_flag_available (part, PED_PARTITION_LBA))
--
2.20.1

View File

@ -0,0 +1,167 @@
From 5a02a03e72dc116d5bcab04b8f2185ee2772b967 Mon Sep 17 00:00:00 2001
From: Hans-Joachim Baader <baader@gmx.net>
Date: Mon, 14 Jan 2019 16:01:07 +0100
Subject: [PATCH] Added support for Windows recovery partition (WINRE) on MBR
Windows 10 uses a recovery partition which is sometimes marked with
partition type 0x27 on MBR systems. It wasn't possible to handle such
a partition with parted. Therefore the partition type PARTITION_MSFT_RECOVERY
is now used properly also on MBR when the flag msftres is set.
Signed-off-by: Brian C. Lane <bcl@redhat.com>
---
doc/C/parted.8 | 2 +-
doc/parted.texi | 4 ++--
libparted/labels/dos.c | 40 ++++++++++++++++++++++++++++++++++++++--
3 files changed, 41 insertions(+), 5 deletions(-)
diff --git a/doc/C/parted.8 b/doc/C/parted.8
index fecdc29..15932c2 100644
--- a/doc/C/parted.8
+++ b/doc/C/parted.8
@@ -112,7 +112,7 @@ or an LVM logical volume if necessary.
.B set \fIpartition\fP \fIflag\fP \fIstate\fP
Change the state of the \fIflag\fP on \fIpartition\fP to \fIstate\fP.
Supported flags are: "boot", "root", "swap", "hidden", "raid", "lvm", "lba",
-"legacy_boot", "irst", "esp" and "palo".
+"legacy_boot", "irst", "msftres", "esp" and "palo".
\fIstate\fP should be either "on" or "off".
.TP
.B unit \fIunit\fP
diff --git a/doc/parted.texi b/doc/parted.texi
index 6f8c378..e124222 100644
--- a/doc/parted.texi
+++ b/doc/parted.texi
@@ -861,8 +861,8 @@ flag can only be removed within parted by replacing it with a competing
flag, such as boot or msftres.
@item msftres
-(GPT) - This flag identifies a "Microsoft Reserved" partition, which is
-used by Windows on GPT disks. Note that this flag should not normally be
+(MS-DOS,GPT) - This flag identifies a "Microsoft Reserved" partition, which
+is used by Windows. Note that this flag should not normally be
set on Windows filesystem partitions (those that contain NTFS or FAT
filesystems).
diff --git a/libparted/labels/dos.c b/libparted/labels/dos.c
index b2b8de9..d736b9e 100644
--- a/libparted/labels/dos.c
+++ b/libparted/labels/dos.c
@@ -156,6 +156,7 @@ typedef struct {
unsigned char system;
int boot;
int hidden;
+ int msftres;
int raid;
int lvm;
int lba;
@@ -949,8 +950,8 @@ raw_part_parse (const PedDisk* disk, const DosRawPartition* raw_part,
dos_data->system = raw_part->type;
dos_data->boot = raw_part->boot_ind != 0;
dos_data->diag = raw_part->type == PARTITION_COMPAQ_DIAG ||
- raw_part->type == PARTITION_MSFT_RECOVERY ||
raw_part->type == PARTITION_DELL_DIAG;
+ dos_data->msftres = raw_part->type == PARTITION_MSFT_RECOVERY;
dos_data->hidden = raw_part_is_hidden (raw_part);
dos_data->raid = raw_part->type == PARTITION_LINUX_RAID;
dos_data->lvm = raw_part->type == PARTITION_LINUX_LVM_OLD
@@ -1345,6 +1346,7 @@ msdos_partition_new (const PedDisk* disk, PedPartitionType part_type,
dos_data->orig = NULL;
dos_data->system = PARTITION_LINUX;
dos_data->hidden = 0;
+ dos_data->msftres = 0;
dos_data->boot = 0;
dos_data->diag = 0;
dos_data->raid = 0;
@@ -1384,6 +1386,7 @@ msdos_partition_duplicate (const PedPartition* part)
new_dos_data->boot = old_dos_data->boot;
new_dos_data->diag = old_dos_data->diag;
new_dos_data->hidden = old_dos_data->hidden;
+ new_dos_data->msftres = old_dos_data->msftres;
new_dos_data->raid = old_dos_data->raid;
new_dos_data->lvm = old_dos_data->lvm;
new_dos_data->lba = old_dos_data->lba;
@@ -1433,6 +1436,11 @@ msdos_partition_set_system (PedPartition* part,
&& strcmp (fs_type->name, "ntfs") != 0)
dos_data->hidden = 0;
+ if (dos_data->msftres
+ && fs_type
+ && strcmp (fs_type->name, "ntfs") != 0)
+ dos_data->msftres = 0;
+
if (part->type & PED_PARTITION_EXTENDED) {
dos_data->diag = 0;
dos_data->raid = 0;
@@ -1452,11 +1460,14 @@ msdos_partition_set_system (PedPartition* part,
/* Don't change the system if it already is a diag type,
otherwise use Compaq as almost all vendors use that. */
if (dos_data->system != PARTITION_COMPAQ_DIAG &&
- dos_data->system != PARTITION_MSFT_RECOVERY &&
dos_data->system != PARTITION_DELL_DIAG)
dos_data->system = PARTITION_COMPAQ_DIAG;
return 1;
}
+ if (dos_data->msftres) {
+ dos_data->system = PARTITION_MSFT_RECOVERY;
+ return 1;
+ }
if (dos_data->lvm) {
dos_data->system = PARTITION_LINUX_LVM;
return 1;
@@ -1516,6 +1527,7 @@ clear_flags (DosPartitionData *dos_data)
{
dos_data->diag = 0;
dos_data->hidden = 0;
+ dos_data->msftres = 0;
dos_data->lvm = 0;
dos_data->palo = 0;
dos_data->prep = 0;
@@ -1552,6 +1564,18 @@ msdos_partition_set_flag (PedPartition* part,
dos_data->hidden = state;
return ped_partition_set_system (part, part->fs_type);
+ case PED_PARTITION_MSFT_RESERVED:
+ if (part->type == PED_PARTITION_EXTENDED) {
+ ped_exception_throw (
+ PED_EXCEPTION_ERROR,
+ PED_EXCEPTION_CANCEL,
+ _("Extended partitions cannot be recovery partitions on "
+ "msdos disk labels."));
+ return 0;
+ }
+ dos_data->msftres = state;
+ return ped_partition_set_system (part, part->fs_type);
+
case PED_PARTITION_BOOT:
dos_data->boot = state;
if (!state)
@@ -1632,6 +1656,12 @@ msdos_partition_get_flag (const PedPartition* part, PedPartitionFlag flag)
else
return dos_data->hidden;
+ case PED_PARTITION_MSFT_RESERVED:
+ if (part->type == PED_PARTITION_EXTENDED)
+ return 0;
+ else
+ return dos_data->msftres;
+
case PED_PARTITION_BOOT:
return dos_data->boot;
@@ -1675,6 +1705,12 @@ msdos_partition_is_flag_available (const PedPartition* part,
else
return 1;
+ case PED_PARTITION_MSFT_RESERVED:
+ if (part->type == PED_PARTITION_EXTENDED)
+ return 0;
+ else
+ return 1;
+
case PED_PARTITION_BOOT:
case PED_PARTITION_RAID:
case PED_PARTITION_LVM:
--
2.20.1

View File

@ -4,7 +4,7 @@
Summary: The GNU disk partition manipulation program
Name: parted
Version: 3.2
Release: 37%{?dist}
Release: 38%{?dist}
License: GPLv3+
URL: http://www.gnu.org/software/parted
@ -121,6 +121,15 @@ Patch0101: 0101-ped_unit_get_name-Resolve-conflicting-attributes-con.patch
Patch0102: 0102-Fix-warnings-from-GCC-7-s-Wimplicit-fallthrough.patch
Patch0103: 0103-Read-NVMe-model-names-from-sysfs.patch
# Missing patches from Wang Dong
Patch0104: 0104-parted-fix-crash-due-to-improper-partition-number-in.patch
Patch0105: 0105-parted-fix-wrong-error-label-jump-in-mkpart.patch
Patch0106: 0106-clean-the-disk-information-when-commands-fail-in-int.patch
Patch0107: 0107-parted-Remove-PED_ASSERT-from-ped_partition_set_name.patch
Patch0108: 0108-Added-support-for-Windows-recovery-partition-WINRE-o.patch
BuildRequires: gcc
BuildRequires: e2fsprogs-devel
BuildRequires: readline-devel
@ -231,6 +240,14 @@ make check
%changelog
* Thu Jan 31 2019 Brian C. Lane <bcl@redhat.com> - 3.2-38
- Add missing patches from Wang Dong
- fix crash due to improper partition number (dongdwdw)
- fix wrong error label jump in mkpart (dongdwdw)
- clean the disk information when commands fail (dongdwdw)
- Remove PED_ASSERT from ped_partition_set_name (bcl)
- Added support for Windows recovery partition (Hans-Joachim.Baader)
* Tue Oct 16 2018 Brian C. Lane <bcl@redhat.com> - 3.2-37
- Read NVMe model names from sysfs (dann.frazier)
- Fix warnings from GCC 7's -Wimplicit-fallthrough (dann.frazier)