dcavalca / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone

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

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