cdown / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone

Blame SOURCES/0101-more-avoid-double-free-on-exit.patch

05ad79
From f98c5f53d4661ec22097d36f5debd195491ec3c6 Mon Sep 17 00:00:00 2001
05ad79
From: Karel Zak <kzak@redhat.com>
05ad79
Date: Thu, 15 Dec 2016 14:40:26 +0100
05ad79
Subject: [PATCH 101/116] more: avoid double free() on exit
05ad79
05ad79
On 'q' command more(1) calls end_it() function with _exit(). The
05ad79
_exit() may suspend program execution due to pending I/O on very
05ad79
loaded server. In this time SIGINT may be delivered due to impatient
05ad79
user who will press ^C.
05ad79
05ad79
And then end_it() cleanup function may be executed by signal handler
05ad79
too. The result is double free()...
05ad79
05ad79
Upstream: https://github.com/karelzak/util-linux/commit/0ed2a954714992938b35893b70197090a61b3b2e
05ad79
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1403971
05ad79
Signed-off-by: Karel Zak <kzak@redhat.com>
05ad79
---
05ad79
 text-utils/more.c | 8 ++++++++
05ad79
 1 file changed, 8 insertions(+)
05ad79
05ad79
diff --git a/text-utils/more.c b/text-utils/more.c
05ad79
index 0e9c2bd..f98cb14 100644
05ad79
--- a/text-utils/more.c
05ad79
+++ b/text-utils/more.c
05ad79
@@ -763,6 +763,14 @@ void chgwinsz(int dummy __attribute__((__unused__)))
05ad79
 /* Clean up terminal state and exit. Also come here if interrupt signal received */
05ad79
 void __attribute__((__noreturn__)) end_it(int dummy __attribute__((__unused__)))
05ad79
 {
05ad79
+	/* May be executed as a signal handler as well as by main process.
05ad79
+	 *
05ad79
+	 * The _exit() may wait for pending I/O for really long time, be sure
05ad79
+	 * that signal handler is not executed in this time to avoid double
05ad79
+	 * de-initialization (free() calls, etc.).
05ad79
+	 */
05ad79
+	signal(SIGINT, SIG_IGN);
05ad79
+
05ad79
 	reset_tty();
05ad79
 	if (clreol) {
05ad79
 		putchar('\r');
05ad79
-- 
05ad79
2.9.3
05ad79