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

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