Blame SOURCES/kexec-tools-2.0.15-makedumpfile-Fix-array-index-out-of-bound-exception.patch

e79652
From e5f96e79d69a1d295f19130da00ec6514d28a8ae Mon Sep 17 00:00:00 2001
e79652
From: Lianbo Jiang <lijiang@redhat.com>
e79652
Date: Tue, 6 Mar 2018 19:07:00 +0900
e79652
Subject: [PATCH] Fix array index out of bound exception
e79652
e79652
A data overflow may lead to a reversal, which may turn a positive
e79652
number into a large negative number, in this case, the string's
e79652
length will exceed the array size(for example, eta: -2147483648s),
e79652
here the array size is defined 16 characters. So, it is nessasary
e79652
to consider some exceptions.
e79652
e79652
Signed-off-by: Lianbo Jiang <lijiang@redhat.com>
e79652
---
e79652
 print_info.c | 21 +++++++++++++--------
e79652
 1 file changed, 13 insertions(+), 8 deletions(-)
e79652
e79652
diff --git a/makedumpfile-1.6.2/print_info.c b/makedumpfile-1.6.2/print_info.c
e79652
index e0e6a27..09e215a 100644
e79652
--- a/makedumpfile-1.6.2/print_info.c
e79652
+++ b/makedumpfile-1.6.2/print_info.c
e79652
@@ -16,6 +16,8 @@
e79652
 #include "print_info.h"
e79652
 #include <time.h>
e79652
 #include <string.h>
e79652
+#include <stdint.h>
e79652
+#include <inttypes.h>
e79652
 
e79652
 #define PROGRESS_MAXLEN		"50"
e79652
 
e79652
@@ -352,18 +354,21 @@ static void calc_delta(struct timeval *tv_start, struct timeval *delta)
e79652
 }
e79652
 
e79652
 /* produce less than 12 bytes on msg */
e79652
-static int eta_to_human_short (int secs, char* msg)
e79652
+static int eta_to_human_short (int64_t secs, char* msg, int maxsize)
e79652
 {
e79652
 	strcpy(msg, "eta: ");
e79652
 	msg += strlen("eta: ");
e79652
 	if (secs < 100)
e79652
-		sprintf(msg, "%ds", secs);
e79652
+		snprintf(msg, maxsize, "%"PRId64"s", secs);
e79652
 	else if (secs < 100 * 60)
e79652
-		sprintf(msg, "%dm%ds", secs / 60, secs % 60);
e79652
+		snprintf(msg, maxsize, "%"PRId64"m""%"PRId64"s",
e79652
+			secs / 60, secs % 60);
e79652
 	else if (secs < 48 * 3600)
e79652
-		sprintf(msg, "%dh%dm", secs / 3600, (secs / 60) % 60);
e79652
+		snprintf(msg, maxsize, "%"PRId64"h""%"PRId64"m",
e79652
+			secs / 3600, (secs / 60) % 60);
e79652
 	else if (secs < 100 * 86400)
e79652
-		sprintf(msg, "%dd%dh", secs / 86400, (secs / 3600) % 24);
e79652
+		snprintf(msg, maxsize, "%"PRId64"d""%"PRId64"h",
e79652
+			secs / 86400, (secs / 3600) % 24);
e79652
 	else
e79652
 		sprintf(msg, ">2day");
e79652
 	return 0;
e79652
@@ -379,8 +384,8 @@ print_progress(const char *msg, unsigned long current, unsigned long end, struct
e79652
 	static unsigned int lapse = 0;
e79652
 	static const char *spinner = "/|\\-";
e79652
 	struct timeval delta;
e79652
-	double eta;
e79652
-	char eta_msg[16] = " ";
e79652
+	int64_t eta;
e79652
+	char eta_msg[32] = " ";
e79652
 
e79652
 	if (current < end) {
e79652
 		tm = time(NULL);
e79652
@@ -395,7 +400,7 @@ print_progress(const char *msg, unsigned long current, unsigned long end, struct
e79652
 		calc_delta(start, &delta);
e79652
 		eta = delta.tv_sec + delta.tv_usec / 1e6;
e79652
 		eta = (100 - progress) * eta / progress;
e79652
-		eta_to_human_short(eta, eta_msg);
e79652
+		eta_to_human_short(eta, eta_msg, sizeof(eta_msg));
e79652
 	}
e79652
 	if (flag_ignore_r_char) {
e79652
 		PROGRESS_MSG("%-" PROGRESS_MAXLEN "s: [%5.1f %%] %c  %16s\n",
e79652
-- 
e79652
2.9.5
e79652