]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
more: avoid double free() on exit
authorKarel Zak <kzak@redhat.com>
Thu, 15 Dec 2016 13:40:26 +0000 (14:40 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 15 Dec 2016 13:40:26 +0000 (14:40 +0100)
On 'q' command more(1) calls end_it() function with _exit(). The
_exit() may suspend program execution due to pending I/O on very
loaded server. In this time SIGINT may be delivered due to impatient
user who will press ^C.

And then end_it() cleanup function may be executed by signal handler
too. The result is double free()...

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1403971
Signed-off-by: Karel Zak <kzak@redhat.com>
text-utils/more.c

index 21e0cbc702ac1d01e0c326706c73f46bd1faeb58..76ba24a17497c138e87a842cc6b46aa1884b7d3a 100644 (file)
@@ -673,6 +673,14 @@ void chgwinsz(int dummy __attribute__((__unused__)))
 /* Clean up terminal state and exit. Also come here if interrupt signal received */
 void __attribute__((__noreturn__)) end_it(int dummy __attribute__((__unused__)))
 {
+       /* May be executed as a signal handler as well as by main process.
+        *
+        * The _exit() may wait for pending I/O for really long time, be sure
+        * that signal handler is not executed in this time to avoid double
+        * de-initialization (free() calls, etc.).
+        */
+       signal(SIGINT, SIG_IGN);
+
        reset_tty();
        if (clreol) {
                putchar('\r');