parted/parted-escape-printed-device-path.patch
Marcus Meissner 5631eac2bb Accepting request 760713 from home:anicka:branches:Base:System
- fix crash in do_resizepart
  + parted-fix-end_input-usage.patch: Fix end_input usage in
    do_resizepart 

- update to version 3.3, noteworthy changes:
 - s390: Re-enabled virtio-attached DASD heuristics by using
   HDIO_GETGEO when probing device geometry. Fixes a bug with
   KVM virtio-blk backed by a DASD.
   Parted now recognizes NVMe devices, NVDIMM, and RAM drives.
 - Fix atari disklabel false positives by probing other labels first.
 - Fix resizepart to adjust the end to be -1 sector when using iec
   power of 2 units so that the next partition can start immediately
   following the new end, just like mkpart does.
 - Fix set and disk_set to not crash when there are no flags to set.
 - Fix a udev cookie leak when using resizepart on device-mapper devices.
 - Fix a gettext crash/error sometimes when using localized languages.
 - Fix fat resize to preverve boot code, and thus not render the
   filesystem unreconized by Windows.
 - Fix rescue command: the rescue command often failed to find
   filesystems due to leaving on cylinder alignment.
 - libparted-fs-resize: Prevent crash resizing FAT file systems with very
   deep directories with path names over 512 bytes long.
 - Use 512b sector size when communicating with device-mapper. Fixes
   problems with partitions being created too small on dm devices
   with sector sizes > 5121b
 - Don't crash in the disk_set command when a disk label is not found
 - libparted-fs-resize: Prevent crash resizing FAT16 file systems.
 - libparted-fs-resize: Prevent crash resizing FAT16 file systems.
 - If the user specifies start/end of the partition as cylinders
   and a cylinder has a size which is power of 2, then such address

OBS-URL: https://build.opensuse.org/request/show/760713
OBS-URL: https://build.opensuse.org/package/show/Base:System/parted?expand=0&rev=144
2020-01-12 13:40:37 +00:00

80 lines
2.6 KiB
Diff

From: Sebastian Parschauer <sparschauer@suse.de>
Date: Tue, 7 Nov 2017 20:14:06 +0100
Subject: parted: Escape printed device path in machine mode
References: bsc#1066467
Patch-mainline: submitted, 2017-11-07
The function _print_disk_info() uses the colon ':' as the separator
but the device path it prints can contain that character as well.
In that case parsing fails.
So introduce the function _escape_machine_string() to allocate an
output string twice as big as the input string and escape ':' and
'\' with a '\'. Print the escaped path and free it again. Ignore
the NULL pointer dereference in out-of-memory situation like it
is done for the other allocations in _print_disk_info() as well.
Resolves: bsc#1066467
Reported-by: Arvin Schnell <aschnell@suse.com>
Signed-off-by: Sebastian Parschauer <sparschauer@suse.de>
---
parted/parted.c | 29 ++++++++++++++++++++++++++++-
1 file changed, 28 insertions(+), 1 deletion(-)
Index: parted-3.3/parted/parted.c
===================================================================
--- parted-3.3.orig/parted/parted.c
+++ parted-3.3/parted/parted.c
@@ -1053,6 +1053,30 @@ _print_disk_geometry (const PedDevice *d
free (cyl_size);
}
+static char *
+_escape_machine_string (const char *str)
+{
+ size_t i, j;
+ char *dest;
+
+ dest = ped_malloc ((strlen(str) + 1) * 2);
+ if (!dest)
+ return NULL;
+
+ for (i = 0, j = 0; str[i] != '\0'; i++, j++) {
+ switch (str[i]) {
+ case ':':
+ case '\\':
+ dest[j++] = '\\';
+ default:
+ dest[j] = str[i];
+ break;
+ }
+ }
+ dest[j] = '\0';
+ return dest;
+}
+
static void
_print_disk_info (const PedDevice *dev, const PedDisk *diskp)
{
@@ -1073,6 +1097,8 @@ _print_disk_info (const PedDevice *dev,
char *disk_flags = disk_print_flags (diskp);
if (opt_machine_mode) {
+ char *path = _escape_machine_string (dev->path);
+
switch (default_unit) {
case PED_UNIT_CHS: puts ("CHS;");
break;
@@ -1083,9 +1109,10 @@ _print_disk_info (const PedDevice *dev,
}
printf ("%s:%s:%s:%lld:%lld:%s:%s:%s;\n",
- dev->path, end, transport[dev->type],
+ path, end, transport[dev->type],
dev->sector_size, dev->phys_sector_size,
pt_name, dev->model, disk_flags);
+ free(path);
} else {
printf (_("Model: %s (%s)\n"),
dev->model, transport[dev->type]);