[PATCH] makedumpfile: bugfix: fix a div-by-zero problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In makedumpfile.c, we want the progress printed 10000 times.
It is tested by:

(num_dumped % per) == 0

where per is num_dumpable / 10000.

However, if num_dumpable less than 10000, num_dumped % per causes a
divide-by-zero problem, triggers a SIGFPE.

This patch makes sure per never be 0.

Signed-off-by: Wang Nan <wangnan0 at huawei.com>
Cc: Atsushi Kumagai <kumagai-atsushi at mxc.nes.nec.co.jp>
Cc: kexec at lists.infradead.org
Cc: Geng Hui <hui.geng at huawei.com>
Cc: Simon Horman <horms at verge.net.au>
---
 makedumpfile.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/makedumpfile.c b/makedumpfile.c
index 23251a1..d71977a 100644
--- a/makedumpfile.c
+++ b/makedumpfile.c
@@ -5621,6 +5621,7 @@ write_elf_pages(struct cache_data *cd_header, struct cache_data *cd_page)
 
 	num_dumpable = get_num_dumpable();
 	per = num_dumpable / 10000;
+	per = per ? per : 1;
 
 	off_seg_load    = info->offset_load_dumpfile;
 	cd_page->offset = info->offset_load_dumpfile;
@@ -5906,6 +5907,7 @@ write_elf_pages_cyclic(struct cache_data *cd_header, struct cache_data *cd_page)
 
 	num_dumpable = info->num_dumpable;
 	per = num_dumpable / 10000;
+	per = per ? per : 1;
 
 	off_seg_load   = info->offset_load_dumpfile;
 	cd_page->offset = info->offset_load_dumpfile;
@@ -6164,6 +6166,7 @@ write_kdump_pages(struct cache_data *cd_header, struct cache_data *cd_page)
 
 	num_dumpable = get_num_dumpable();
 	per = num_dumpable / 10000;
+	per = per ? per : 1;
 
 	/*
 	 * Calculate the offset of the page data.
@@ -6365,6 +6368,7 @@ write_kdump_pages_cyclic(struct cache_data *cd_header, struct cache_data *cd_pag
 	}
 
 	per = info->num_dumpable / 10000;
+	per = per ? per : 1;
 
 	/*
 	 * Set a fileoffset of Physical Address 0x0.
-- 
1.8.4




[Index of Archives]     [LM Sensors]     [Linux Sound]     [ALSA Users]     [ALSA Devel]     [Linux Audio Users]     [Linux Media]     [Kernel]     [Gimp]     [Yosemite News]     [Linux Media]

  Powered by Linux