public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
From: Vitezslav Crhonek <vcrhonek@redhat.com>
To: git-commits@fedoraproject.org
Subject: [rpms/expect] f44: Fix segfault on Ctrl-C when tclreadline is loaded
Date: Mon, 31 Aug 2026 09:49:17 GMT	[thread overview]
Message-ID: <178816975748.1.10426647877806767775.rpms-expect-fc81295edadc@fedoraproject.org> (raw)

A new commit has been pushed.

Repo   : rpms/expect
Branch : f44
Commit : fc81295edadc62144195e9fcff18134851319ba7
Author : Vitezslav Crhonek <vcrhonek@redhat.com>
Date   : 2026-08-31T11:49:06+02:00
Stats  : +72/-1 in 2 file(s)
URL    : https://src.fedoraproject.org/rpms/expect/c/fc81295edadc62144195e9fcff18134851319ba7?branch=f44

Log:
Fix segfault on Ctrl-C when tclreadline is loaded

---
diff --git a/expect-5.45.4-exit-sighandler.patch b/expect-5.45.4-exit-sighandler.patch
new file mode 100644
index 0000000..da4c127
--- /dev/null
+++ b/expect-5.45.4-exit-sighandler.patch
@@ -0,0 +1,64 @@
+diff -up expect5.45.4/exp_command.c.exit-sighandler expect5.45.4/exp_command.c
+--- expect5.45.4/exp_command.c.exit-sighandler	2026-08-18 10:47:10.722479406 +0200
++++ expect5.45.4/exp_command.c	2026-08-18 13:01:09.524036587 +0200
+@@ -2516,6 +2516,30 @@ Exp_ExitObjCmd(
+     }
+
+     /*
++     * When exit is called from a signal trap handler (e.g., the default
++     * SIGINT handler runs "exit 130" on Ctrl-C), we may be deep inside
++     * Tcl's event loop via Tcl_AsyncInvoke.  Calling Tcl_Exit in that
++     * context crashes because FinalizeThread tears down the event system
++     * (epoll file descriptors, channel handlers) while it is still in use
++     * on the call stack.  Restore the terminal and exit immediately.
++     */
++    if (exp_in_signal_handler()) {
++	if (exp_onexit_action) {
++	    Tcl_GlobalEval(interp, exp_onexit_action);
++	}
++
++	if (!exp_disconnected
++	    && !exp_forked
++	    && (exp_dev_tty != -1)
++	    && isatty(exp_dev_tty)) {
++	    if (exp_ioctled_devtty) {
++		exp_tty_set(interp, &exp_tty_original, exp_dev_tty, 0);
++	    }
++	}
++	_exit(value);
++    }
++
++    /*
+      * Restore previous definition of close.  Needed when expect is
+      * dynamically loaded after close has been redefined
+      * e.g.  the virtual file system in tclkit
+diff -up expect5.45.4/exp_command.h.exit-sighandler expect5.45.4/exp_command.h
+--- expect5.45.4/exp_command.h.exit-sighandler	2026-08-18 10:47:10.721479410 +0200
++++ expect5.45.4/exp_command.h	2026-08-18 10:51:06.973377387 +0200
+@@ -249,6 +249,7 @@ EXTERN int		exp_2tcl_returnvalue (int);
+ EXTERN void		exp_rearm_sigchld (Tcl_Interp *);
+ EXTERN int		exp_string_to_signal (Tcl_Interp *,char *);
+
++EXTERN int		exp_in_signal_handler (void);
+ EXTERN char *exp_onexit_action;
+
+ #define exp_new(x)	(x *)malloc(sizeof(x))
+diff -up expect5.45.4/exp_trap.c.exit-sighandler expect5.45.4/exp_trap.c
+--- expect5.45.4/exp_trap.c.exit-sighandler	2026-08-18 10:47:10.720479415 +0200
++++ expect5.45.4/exp_trap.c	2026-08-18 10:50:59.578411909 +0200
+@@ -77,6 +77,15 @@ static int current_sig = NO_SIG;
+ int exp_nostack_dump = FALSE;	/* TRUE if user has requested unrolling of */
+ 				/* stack with no trace */
+
++/* Return whether we are currently inside a signal trap handler.
++ * This is used by Exp_ExitObjCmd to avoid calling Tcl_Exit from within
++ * event processing (via Tcl_AsyncInvoke), which would crash because
++ * Tcl_Exit tears down the event system while it is still in use. */
++int
++exp_in_signal_handler(void)
++{
++	return current_sig != NO_SIG;
++}
+
+
+ /*ARGSUSED*/

diff --git a/expect.spec b/expect.spec
index 85dbbf7..9ef67a7 100644
--- a/expect.spec
+++ b/expect.spec
@@ -5,7 +5,7 @@
 Summary: A program-script interaction and testing utility
 Name: expect
 Version: %{majorver}
-Release: 32%{?dist}
+Release: 33%{?dist}
 License: LicenseRef-Fedora-Public-Domain
 URL: https://core.tcl.tk/expect/index
 Source: http://downloads.sourceforge.net/%{name}/%{name}%{version}.tar.gz
@@ -53,6 +53,8 @@ Patch17: expect-5.45.4-tcl9-eval-tokens.patch
 Patch18: expect-5.45.4-tcl9-alloc.patch
 # Patch19: update int to Tcl_Size for tcl9 API changes, fix function signatures
 Patch19: expect-5.45.4-tcl9-size.patch
+# Patch20: fix segfault when Ctrl-C is pressed with tclreadline loaded, rhbz#2497646
+Patch20: expect-5.45.4-exit-sighandler.patch
 # examples patches
 # Patch100: changes random function
 Patch100: expect-5.32.2-random.patch
@@ -128,6 +130,7 @@ of expectk.
 %patch -P17 -p1 -b .tcl9-eval-tokens
 %patch -P18 -p1 -b .tcl9-alloc
 %patch -P19 -p1 -b .tcl9-size
+%patch -P20 -p1 -b .exit-sighandler
 # examples fixes
 %patch -P100 -p1 -b .random
 %patch -P101 -p1 -b .mkpasswd-dash
@@ -219,6 +222,10 @@ chrpath --delete $RPM_BUILD_ROOT%{_libdir}/libexpect%{version}.so
 %{_mandir}/man1/tknewsbiff.1*
 
 %changelog
+* Mon Aug 31 2026 Vitezslav Crhonek <vcrhonek@redhat.com> - 5.45.4-33
+- Fix segfault on Ctrl-C when tclreadline is loaded
+  Resolves: #2497646
+
 * Wed Jun 17 2026 Florian Weimer  <fweimer@redhat.com> - 5.45.4-32
 - Use binary mode in unbuffer (#2489967)
 

                 reply	other threads:[~2026-08-31  9:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=178816975748.1.10426647877806767775.rpms-expect-fc81295edadc@fedoraproject.org \
    --to=vcrhonek@redhat.com \
    --cc=git-commits@fedoraproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox