public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug tui/30056] New: double free when using reverse-search for a previous command and Ctrl-C
@ 2023-01-26 17:47 etesta at undo dot io
  2023-01-27  3:04 ` [Bug tui/30056] " sam at gentoo dot org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: etesta at undo dot io @ 2023-01-26 17:47 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=30056

            Bug ID: 30056
           Summary: double free when using reverse-search for a previous
                    command and Ctrl-C
           Product: gdb
           Version: 12.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: tui
          Assignee: unassigned at sourceware dot org
          Reporter: etesta at undo dot io
  Target Milestone: ---

The sequence of actions to load a program: "gdb my_file" and then

1) (gdb) start
2) (gdb) layout src
3) Ctrl-r - type anything
4) right arrow
5) Ctrl-C

the following message appears on the screen (tested with 9.2, 10.2 and 12.1):

(gdb) free(): double free detected in tcache 2


                                             Fatal signal:

                                                            Segmentation fault
(core dumped)

A bit of analysis showed the following:

Before the signal is delivered gdb is in __libc_read() as part of the isearch()
stack:

#0  __libc_read (nbytes=1, buf=0x7ffcca50d2f0, fd=0) at
../sysdeps/unix/sysv/linux/read.c:26
#1  __libc_read (fd=0, buf=buf@entry=0x7ffcca50d2f0, nbytes=nbytes@entry=1) at
../sysdeps/unix/sysv/linux/read.c:24
#2  0x00007f9a63a1fdf7 in fifo_push (sp=0xd5d5c00) at
.././ncurses-6.3/ncurses/base/lib_getch.c:349
#3  kgetch (forever=<optimised out>, sp=0xd5d5c00) at
.././ncurses-6.3/ncurses/base/lib_getch.c:733
#4  _nc_wgetch (win=win@entry=0xd36af90, result=result@entry=0x7ffcca50d3cc,
use_meta=<optimised out>) at .././ncurses-6.3/ncurses/base/lib_getch.c:564
#5  0x00007f9a63a207d7 in wgetch (win=win@entry=0xd36af90) at
.././ncurses-6.3/ncurses/base/lib_getch.c:694
#6  0x0000000000947735 in gdb_wgetch (win=0xd36af90) at
.././gdb-10.2/gdb/tui/tui-io.c:681
#7  tui_getc_1 (fp=<optimised out>) at .././gdb-10.2/gdb/tui/tui-io.c:960
#8  tui_getc (fp=<optimised out>) at .././gdb-10.2/gdb/tui/tui-io.c:1039
#9  0x00000000009a3f45 in rl_read_key () at
../.././gdb-10.2/readline/readline/input.c:495
#10 rl_read_key () at ../.././gdb-10.2/readline/readline/input.c:455
#11 0x00000000009a408d in _rl_read_mbstring (first=<optimised out>,
mb=mb@entry=0x3f967b0 "", mlen=mlen@entry=16) at
../.././gdb-10.2/readline/readline/input.c:686
#12 0x000000000099a259 in _rl_search_getchar (cxt=0x3f96740) at
../.././gdb-10.2/readline/readline/isearch.c:314
#13 0x000000000099b1d9 in _rl_isearch_callback (cxt=0x3f96740) at
../.././gdb-10.2/readline/readline/isearch.c:823
#14 0x00000000009a4546 in rl_callback_read_char () at
../.././gdb-10.2/readline/readline/callback.c:164
#15 0x00000000006b563e in gdb_rl_callback_read_char_wrapper_noexcept () at
.././gdb-10.2/gdb/event-top.c:177
#16 0x00000000006b660e in gdb_rl_callback_read_char_wrapper
(client_data=<optimised out>) at .././gdb-10.2/gdb/event-top.c:194
#17 0x00000000006b5580 in stdin_event_handler (error=<optimised out>,
client_data=0x3f27170) at .././gdb-10.2/gdb/event-top.c:516
#18 0x0000000000dc21d5 in gdb_wait_for_event (block=block@entry=1) at
.././gdb-10.2/gdbsupport/event-loop.cc:673
#19 0x0000000000dc22ad in gdb_wait_for_event (block=1) at
.././gdb-10.2/gdbsupport/event-loop.cc:569
#20 gdb_do_one_event () at .././gdb-10.2/gdbsupport/event-loop.cc:215
#21 0x00000000007709e5 in start_event_loop () at .././gdb-10.2/gdb/main.c:356



The first free happens in _rl_scxt_dispose() as part of the following call
stack:

#0  0x000000000099a1d2 in _rl_scxt_dispose (cxt=cxt@entry=0x3f96740,
flags=flags@entry=0) at ../.././gdb-10.2/readline/readline/isearch.c:128
#1  0x000000000099aeb9 in _rl_isearch_cleanup (cxt=0x3f96740, r=r@entry=0) at
../.././gdb-10.2/readline/readline/isearch.c:768
#2  0x00000000009a4816 in rl_callback_sigcleanup () at
../.././gdb-10.2/readline/readline/callback.c:343
#3  0x00000000009a144f in _rl_handle_signal (sig=2) at
../.././gdb-10.2/readline/readline/signals.c:218
#4  0x00000000009a1504 in _rl_signal_handler (sig=<optimised out>) at
../.././gdb-10.2/readline/readline/signals.c:158
#5  0x00000000009a3eea in rl_read_key () at
../.././gdb-10.2/readline/readline/input.c:497
#6  rl_read_key () at ../.././gdb-10.2/readline/readline/input.c:455
#7  0x00000000009a408d in _rl_read_mbstring (first=<optimised out>,
mb=mb@entry=0x3f967b0 "", mlen=mlen@entry=16) at
../.././gdb-10.2/readline/readline/input.c:686
#8  0x000000000099a259 in _rl_search_getchar (cxt=0x3f96740) at
../.././gdb-10.2/readline/readline/isearch.c:314
#9  0x000000000099b1d9 in _rl_isearch_callback (cxt=0x3f96740) at
../.././gdb-10.2/readline/readline/isearch.c:823
#10 0x00000000009a4546 in rl_callback_read_char () at
../.././gdb-10.2/readline/readline/callback.c:164
#11 0x00000000006b563e in gdb_rl_callback_read_char_wrapper_noexcept () at
.././gdb-10.2/gdb/event-top.c:177
#12 0x00000000006b660e in gdb_rl_callback_read_char_wrapper
(client_data=<optimised out>) at .././gdb-10.2/gdb/event-top.c:194
#13 0x00000000006b5580 in stdin_event_handler (error=<optimised out>,
client_data=0x3f27170) at .././gdb-10.2/gdb/event-top.c:516
#14 0x0000000000dc21d5 in gdb_wait_for_event (block=block@entry=1) at
.././gdb-10.2/gdbsupport/event-loop.cc:673
#15 0x0000000000dc22ad in gdb_wait_for_event (block=1) at
.././gdb-10.2/gdbsupport/event-loop.cc:569
#16 gdb_do_one_event () at .././gdb-10.2/gdbsupport/event-loop.cc:215
#17 0x00000000007709e5 in start_event_loop () at .././gdb-10.2/gdb/main.c:356

the second free happens in _rl_scxt_dispose() again but the call stack is
different:

#0  _rl_scxt_dispose (cxt=cxt@entry=0x3f96740, flags=flags@entry=0) at
../.././gdb-10.2/readline/readline/isearch.c:125
#1  0x000000000099aeb9 in _rl_isearch_cleanup (cxt=0x3f96740, r=-1) at
../.././gdb-10.2/readline/readline/isearch.c:768
#2  0x000000000099b1fb in _rl_isearch_callback (cxt=<optimised out>) at
../.././gdb-10.2/readline/readline/isearch.c:827
#3  0x00000000009a4546 in rl_callback_read_char () at
../.././gdb-10.2/readline/readline/callback.c:164
#4  0x00000000006b563e in gdb_rl_callback_read_char_wrapper_noexcept () at
.././gdb-10.2/gdb/event-top.c:177
#5  0x00000000006b660e in gdb_rl_callback_read_char_wrapper
(client_data=<optimised out>) at .././gdb-10.2/gdb/event-top.c:194
#6  0x00000000006b5580 in stdin_event_handler (error=<optimised out>,
client_data=0x3f27170) at .././gdb-10.2/gdb/event-top.c:516
#7  0x0000000000dc21d5 in gdb_wait_for_event (block=block@entry=1) at
.././gdb-10.2/gdbsupport/event-loop.cc:673
#8  0x0000000000dc22ad in gdb_wait_for_event (block=1) at
.././gdb-10.2/gdbsupport/event-loop.cc:569
#9  gdb_do_one_event () at .././gdb-10.2/gdbsupport/event-loop.cc:215
#10 0x00000000007709e5 in start_event_loop () at .././gdb-10.2/gdb/main.c:356


It looks like that as part of the signal handling the isearch context is being
clered up and once the signal handler finishes the search fails (correctly)
but it tries to free its own context again and thus it gets the double free.

I can provide more information if required. I have a GDB recording I can use to
analyze the bug further if needed.

Best Regards

Emiliano

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-05-28  8:27 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-26 17:47 [Bug tui/30056] New: double free when using reverse-search for a previous command and Ctrl-C etesta at undo dot io
2023-01-27  3:04 ` [Bug tui/30056] " sam at gentoo dot org
2023-01-28 20:00 ` ssbssa at sourceware dot org
2023-05-23  8:38 ` vries at gcc dot gnu.org
2023-05-23  9:53 ` vries at gcc dot gnu.org
2023-05-23 10:29 ` vries at gcc dot gnu.org
2023-05-23 11:50 ` vries at gcc dot gnu.org
2023-05-23 15:06 ` vries at gcc dot gnu.org
2023-05-23 16:06 ` vries at gcc dot gnu.org
2023-05-24 14:11 ` vries at gcc dot gnu.org
2023-05-28  8:17 ` cvs-commit at gcc dot gnu.org
2023-05-28  8:27 ` vries at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).