Blame SOURCES/0197-col-make-flush_line-a-little-bit-robust.patch

dd89d8
From 32eb48b3590b3f3a6a4519d51a2ccbf6c6c6398e Mon Sep 17 00:00:00 2001
dd89d8
From: Karel Zak <kzak@redhat.com>
dd89d8
Date: Tue, 5 Feb 2019 12:06:00 +0100
dd89d8
Subject: [PATCH 197/197] col: make flush_line() a little bit robust
dd89d8
dd89d8
The code is horrible. The core of the problem are signed integers
dd89d8
and no check for the limits.
dd89d8
dd89d8
This patch fixes c->c_column = cur_col; where c_column is "short"
dd89d8
and "cur_col" is int. Let's use "int" for all the variables. It's
dd89d8
really not perfect as for bigger lines it can segfault again...
dd89d8
dd89d8
The patch also removes some unnecessary static variables.
dd89d8
dd89d8
[kzak@redhat.com: - RHEL-7: keep warn() output unchanged]
dd89d8
dd89d8
Addresses: https://github.com/karelzak/util-linux/issues/749
dd89d8
Upstream: http://github.com/karelzak/util-linux/commit/004356f05018e3bfcaddd2652846659a4d8481f3
dd89d8
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1784579
dd89d8
Signed-off-by: Karel Zak <kzak@redhat.com>
dd89d8
---
dd89d8
 text-utils/col.c | 11 ++++++-----
dd89d8
 1 file changed, 6 insertions(+), 5 deletions(-)
dd89d8
dd89d8
diff --git a/text-utils/col.c b/text-utils/col.c
dd89d8
index 9aa6a414b..0dd6ea431 100644
dd89d8
--- a/text-utils/col.c
dd89d8
+++ b/text-utils/col.c
dd89d8
@@ -79,7 +79,7 @@ typedef char CSET;
dd89d8
 typedef struct char_str {
dd89d8
 #define	CS_NORMAL	1
dd89d8
 #define	CS_ALTERNATE	2
dd89d8
-	short		c_column;	/* column character is in */
dd89d8
+	int		c_column;	/* column character is in */
dd89d8
 	CSET		c_set;		/* character set (currently only 2) */
dd89d8
 	wchar_t		c_char;		/* character in question */
dd89d8
 	int		c_width;	/* character width */
dd89d8
@@ -451,8 +451,9 @@ void flush_line(LINE *l)
dd89d8
 	nchars = l->l_line_len;
dd89d8
 
dd89d8
 	if (l->l_needs_sort) {
dd89d8
-		static CHAR *sorted;
dd89d8
-		static int count_size, *count, i, save, sorted_size, tot;
dd89d8
+		static CHAR *sorted = NULL;
dd89d8
+		static int count_size = 0, *count = NULL, sorted_size = 0;
dd89d8
+		int i, tot;
dd89d8
 
dd89d8
 		/*
dd89d8
 		 * Do an O(n) sort on l->l_line by column being careful to
dd89d8
@@ -469,7 +470,7 @@ void flush_line(LINE *l)
dd89d8
 			    (unsigned)sizeof(int) * count_size);
dd89d8
 		}
dd89d8
 		memset(count, 0, sizeof(int) * l->l_max_col + 1);
dd89d8
-		for (i = nchars, c = l->l_line; --i >= 0; c++)
dd89d8
+		for (i = nchars, c = l->l_line; c && --i >= 0; c++)
dd89d8
 			count[c->c_column]++;
dd89d8
 
dd89d8
 		/*
dd89d8
@@ -477,7 +478,7 @@ void flush_line(LINE *l)
dd89d8
 		 * indices into new line.
dd89d8
 		 */
dd89d8
 		for (tot = 0, i = 0; i <= l->l_max_col; i++) {
dd89d8
-			save = count[i];
dd89d8
+			int save = count[i];
dd89d8
 			count[i] = tot;
dd89d8
 			tot += save;
dd89d8
 		}
dd89d8
-- 
dd89d8
2.25.2
dd89d8