cdown / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone

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

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