Blame SOURCES/0084-Fix-the-length-of-several-strncpy-calls.patch

0cb0b9
From 531eb00aaa03f448cdb3f0c647db7f8d4544c50a Mon Sep 17 00:00:00 2001
0cb0b9
From: "Brian C. Lane" <bcl@redhat.com>
0cb0b9
Date: Mon, 23 Jul 2018 14:34:30 -0700
0cb0b9
Subject: [PATCH 84/88] Fix the length of several strncpy calls
0cb0b9
0cb0b9
These need to be 1 less than the allocated size of the buffer, strncpy
0cb0b9
will fill shorter strings with zeros, but there needs to be room for at
0cb0b9
least one 0x00 at the end if the string is the same length as the buffer
0cb0b9
and has no terminating 0x00.
0cb0b9
0cb0b9
Related: rhbz#1602652
0cb0b9
---
0cb0b9
 libparted/arch/linux.c | 12 ++++++++----
0cb0b9
 libparted/labels/mac.c |  9 ++++++---
0cb0b9
 2 files changed, 14 insertions(+), 7 deletions(-)
0cb0b9
0cb0b9
diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
0cb0b9
index 1c26b8c..dd4820d 100644
0cb0b9
--- a/libparted/arch/linux.c
0cb0b9
+++ b/libparted/arch/linux.c
0cb0b9
@@ -2571,9 +2571,12 @@ _blkpg_add_partition (PedDisk* disk, const PedPartition *part)
0cb0b9
                 linux_part.length = part->geom.length * disk->dev->sector_size;
0cb0b9
         }
0cb0b9
         linux_part.pno = part->num;
0cb0b9
-        strncpy (linux_part.devname, dev_name, BLKPG_DEVNAMELTH);
0cb0b9
-        if (vol_name)
0cb0b9
-                strncpy (linux_part.volname, vol_name, BLKPG_VOLNAMELTH);
0cb0b9
+        strncpy (linux_part.devname, dev_name, BLKPG_DEVNAMELTH-1);
0cb0b9
+        linux_part.devname[BLKPG_DEVNAMELTH-1] = '\0';
0cb0b9
+        if (vol_name) {
0cb0b9
+                strncpy (linux_part.volname, vol_name, BLKPG_VOLNAMELTH-1);
0cb0b9
+                linux_part.volname[BLKPG_VOLNAMELTH-1] = '\0';
0cb0b9
+        }
0cb0b9
 
0cb0b9
         free (dev_name);
0cb0b9
 
0cb0b9
@@ -2629,7 +2632,8 @@ static int _blkpg_resize_partition (PedDisk* disk, const PedPartition *part)
0cb0b9
         else
0cb0b9
                 linux_part.length = part->geom.length * disk->dev->sector_size;
0cb0b9
         linux_part.pno = part->num;
0cb0b9
-        strncpy (linux_part.devname, dev_name, BLKPG_DEVNAMELTH);
0cb0b9
+        strncpy (linux_part.devname, dev_name, BLKPG_DEVNAMELTH-1);
0cb0b9
+        linux_part.devname[BLKPG_DEVNAMELTH-1] = '\0';
0cb0b9
 
0cb0b9
         free (dev_name);
0cb0b9
 
0cb0b9
diff --git a/libparted/labels/mac.c b/libparted/labels/mac.c
0cb0b9
index fa4e43f..4942c82 100644
0cb0b9
--- a/libparted/labels/mac.c
0cb0b9
+++ b/libparted/labels/mac.c
0cb0b9
@@ -930,8 +930,10 @@ _generate_raw_part (PedDisk* disk, PedPartition* part,
0cb0b9
 		= PED_CPU_TO_BE32 (mac_disk_data->last_part_entry_num);
0cb0b9
 	part_map_entry->start_block = PED_CPU_TO_BE32 (part->geom.start);
0cb0b9
 	part_map_entry->block_count = PED_CPU_TO_BE32 (part->geom.length);
0cb0b9
-	strncpy (part_map_entry->name, mac_part_data->volume_name, 32);
0cb0b9
-	strncpy (part_map_entry->type, mac_part_data->system_name, 32);
0cb0b9
+	strncpy (part_map_entry->name, mac_part_data->volume_name, 31);
0cb0b9
+	part_map_entry->name[31] = '\0';
0cb0b9
+	strncpy (part_map_entry->type, mac_part_data->system_name, 31);
0cb0b9
+	part_map_entry->type[31] = '\0';
0cb0b9
 
0cb0b9
 	if (mac_part_data->is_driver) {
0cb0b9
 		if (mac_part_data->has_driver)
0cb0b9
@@ -954,7 +956,8 @@ _generate_raw_part (PedDisk* disk, PedPartition* part,
0cb0b9
 	part_map_entry->boot_cksum =
0cb0b9
 		PED_CPU_TO_BE32 (mac_part_data->boot_checksum);
0cb0b9
 
0cb0b9
-	strncpy (part_map_entry->processor, mac_part_data->processor_name, 16);
0cb0b9
+	strncpy (part_map_entry->processor, mac_part_data->processor_name, 15);
0cb0b9
+	part_map_entry->processor[15] = '\0';
0cb0b9
 
0cb0b9
 	if (!_pad_raw_part (disk, part->num, part_map))
0cb0b9
 		goto error;
0cb0b9
-- 
0cb0b9
2.17.1
0cb0b9