Hi,

We've found that applications implementing SIGINT handlers consistently
produce segfaults when a SIGINT is sent during a reverse search. We're
running readline-8.3_p1 running on Gentoo ( x86_64 ). This impacts the
MariaDB client at a minimum, but is easily reproducible with a toy program.

Minimal example for reproduction:
input: Ctrl-r, Ctrl-c, <any character> to the following program:

#include <stdio.h>
#include <readline/readline.h>
#include <signal.h>

void sigint_handler(int sig)
{
    return;
}

int main(void)
{
    signal(SIGINT, sigint_handler);

    char *line;

    while (1) {

        line = readline("test> ");

        if (!line)
            break;

        printf("You a typed: %s\n", line);
    }

    return 0;
}

This seems like a side effect of the _rl_state_sigcleanup introduced here:
https://cgit.git.savannah.gnu.org/cgit/readline.git/diff/signals.c?id=447b8290b3e2e2d117dc8e9cdb83b0dc6448a638
, since now any program re-entering into the _rl_search_getchar() function
from a _rl_signal_handler() call is referring to a cxt->search_string
that's already been freed by the new call to _rl_isearch_cleanup().

It looks like this impacts any programs that implement their own SIGINT
handler and rely on the 'standard'  Readline Signal handling documented
here:
https://tiswww.case.edu/php/chet/readline/readline.html#Readline-Signal-Handling
, specifically impacting the mariadb client:
https://github.com/MariaDB/server/blob/main/client/mysql.cc#L1600 .

Happy to patch downstream applications where necessary if that's the path
forward, but I wasn't able to find a downstream solution that aligns with
readline's documentation (happy to be corrected, here).

Warmest regards,
Aden

Reply via email to