Blame SOURCES/kexec-tools-2.0.7-makedumpfile-sadump-fix-segmentation-fault-on-sadump-re.patch

e35838
From 8edf033f0eada8640f821ea8abd5bc2b0fa09083 Mon Sep 17 00:00:00 2001
e35838
From: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
e35838
Date: Mon, 20 Jun 2016 14:58:05 +0900
e35838
Subject: [PATCH 1/2] [PATCH 1/2] sadump: fix segmentation fault on
e35838
 sadump-related formats
e35838
e35838
Currently, makedumpfile results in segmentation fault on
e35838
sadump-related formats:
e35838
e35838
    # ~/makedumpfile --message-level 31 -l -d 31 -x ./vmlinux vmcore
e35838
    sadump: read dump device as single partition
e35838
    sadump: single partition configuration
e35838
    page_size    : 4096
e35838
    Segmentation fault
e35838
e35838
This is because although commit
e35838
5fc24bf754fa6d2c0bd0f1c6f5655de371efb9d5 started dynamically
e35838
allocating the buffer of struct dump_bitmap, the sadump source code
e35838
doesn't follow the change.
e35838
e35838
This commit fixes this by following the change.
e35838
e35838
Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
e35838
Signed-off-by: Baoquan He <bhe@redhat.com>
e35838
---
e35838
 makedumpfile.c |  5 ++++-
e35838
 sadump_info.c  | 28 ++++++++++++++++++++++++++--
e35838
 2 files changed, 30 insertions(+), 3 deletions(-)
e35838
e35838
diff --git a/makedumpfile-1.6.0/makedumpfile.c b/makedumpfile-1.6.0/makedumpfile.c
e35838
index fd884d3..ee3174f 100644
e35838
--- a/makedumpfile-1.6.0/makedumpfile.c
e35838
+++ b/makedumpfile-1.6.0/makedumpfile.c
e35838
@@ -11245,8 +11245,11 @@ out:
e35838
 			free(info->kh_memory);
e35838
 		if (info->valid_pages)
e35838
 			free(info->valid_pages);
e35838
-		if (info->bitmap_memory)
e35838
+		if (info->bitmap_memory) {
e35838
+			if (info->bitmap_memory->buf)
e35838
+				free(info->bitmap_memory->buf);
e35838
 			free(info->bitmap_memory);
e35838
+		}
e35838
 		if (info->fd_memory)
e35838
 			close(info->fd_memory);
e35838
 		if (info->fd_dumpfile)
e35838
diff --git a/makedumpfile-1.6.0/sadump_info.c b/makedumpfile-1.6.0/sadump_info.c
e35838
index 20376f0..8716167 100644
e35838
--- a/makedumpfile-1.6.0/sadump_info.c
e35838
+++ b/makedumpfile-1.6.0/sadump_info.c
e35838
@@ -832,18 +832,28 @@ sadump_initialize_bitmap_memory(void)
e35838
 		       strerror(errno));
e35838
 		return FALSE;
e35838
 	}
e35838
+
e35838
 	bmp->fd = info->fd_memory;
e35838
 	bmp->file_name = info->name_memory;
e35838
 	bmp->no_block = -1;
e35838
-	memset(bmp->buf, 0, BUFSIZE_BITMAP);
e35838
 	bmp->offset = dumpable_bitmap_offset;
e35838
 
e35838
+	bmp->buf = malloc(BUFSIZE_BITMAP);
e35838
+	if (!bmp->buf) {
e35838
+		ERRMSG("Can't allocate memory for the memory-bitmap's buffer. %s\n",
e35838
+		       strerror(errno));
e35838
+		free(bmp);
e35838
+		return FALSE;
e35838
+	}
e35838
+	memset(bmp->buf, 0, BUFSIZE_BITMAP);
e35838
+
e35838
 	max_section = divideup(si->max_mapnr, SADUMP_PF_SECTION_NUM);
e35838
 
e35838
 	block_table = calloc(sizeof(unsigned long long), max_section);
e35838
 	if (block_table == NULL) {
e35838
 		ERRMSG("Can't allocate memory for the block_table. %s\n",
e35838
 		       strerror(errno));
e35838
+		free(bmp->buf);
e35838
 		free(bmp);
e35838
 		return FALSE;
e35838
 	}
e35838
@@ -870,8 +880,17 @@ sadump_initialize_bitmap_memory(void)
e35838
 	bmp->fd = info->fd_memory;
e35838
 	bmp->file_name = info->name_memory;
e35838
 	bmp->no_block = -1;
e35838
-	memset(bmp->buf, 0, BUFSIZE_BITMAP);
e35838
 	bmp->offset = si->sub_hdr_offset + sh->block_size * sh->sub_hdr_size;
e35838
+
e35838
+	bmp->buf = malloc(BUFSIZE_BITMAP);
e35838
+	if (!bmp->buf) {
e35838
+		ERRMSG("Can't allocate memory for the memory-bitmap's buffer. %s\n",
e35838
+		       strerror(errno));
e35838
+		free(bmp);
e35838
+		return FALSE;
e35838
+	}
e35838
+	memset(bmp->buf, 0, BUFSIZE_BITMAP);
e35838
+
e35838
 	si->ram_bitmap = bmp;
e35838
 
e35838
 	/*
e35838
@@ -1904,6 +1923,11 @@ free_sadump_info(void)
e35838
 		fclose(si->file_elf_note);
e35838
 	if (si->cpu_online_mask_buf)
e35838
 		free(si->cpu_online_mask_buf);
e35838
+	if (si->ram_bitmap) {
e35838
+		if (si->ram_bitmap->buf)
e35838
+			free(si->ram_bitmap->buf);
e35838
+		free(si->ram_bitmap);
e35838
+	}
e35838
 }
e35838
 
e35838
 void
e35838
-- 
e35838
2.5.5
e35838