binutils-gdb/gdb/cli
Lancelot SIX 59b59f08f6 Avoid use after free with logging and debug redirect.
This patch addresses PR gdb/27133. Before it, the following succession
of commands would cause gdb to crash:

	set logging redirect on
	set logging debugredirect on
	set logging on

The problem eventually comes down to a use after free. The function
cli_interp_base::set_logging is called with a unique_ptr argument that
holds a pointer to the redirection file. In the problematic use case,
no-one ever took ownership of that pointer (as far as unique_ptr is
concerned), so the call to its dtor at the end of the function causes
the file object to be deleted. Any later use of the pointer to the
redirection file is therefore an error.

This patch ensures that the unique_ptr is released  when required (so it
does not assume ownership anymore). The internal logic of
cli_interp_base::set_logging takes care of freeing the ui_file when it
is not necessary anymore using the saved_output.file_to_delete field.

gdb/ChangeLog:

	PR gdb/27133
	* cli/cli-interp.c (cli_interp_base::set_logging): Ensure the
	unique_ptr is released when the wrapped pointer is kept for later
	use.

gdb/testsuite/ChangeLog:

	PR gdb/27133
	* gdb.base/ui-redirect.exp: Add test case that ensures that
	redirecting both logging and debug does not cause gdb to crash.
2021-01-27 22:09:52 +00:00
..
cli-cmds.c gdb: move set remote commands to remote.c 2021-01-22 12:35:54 -05:00
cli-cmds.h Update copyright year range in all GDB files 2021-01-01 12:12:21 +04:00
cli-decode.c Update copyright year range in all GDB files 2021-01-01 12:12:21 +04:00
cli-decode.h Update copyright year range in all GDB files 2021-01-01 12:12:21 +04:00
cli-dump.c Update copyright year range in all GDB files 2021-01-01 12:12:21 +04:00
cli-interp.c Avoid use after free with logging and debug redirect. 2021-01-27 22:09:52 +00:00
cli-interp.h Update copyright year range in all GDB files 2021-01-01 12:12:21 +04:00
cli-logging.c Update copyright year range in all GDB files 2021-01-01 12:12:21 +04:00
cli-option.c Update copyright year range in all GDB files 2021-01-01 12:12:21 +04:00
cli-option.h Update copyright year range in all GDB files 2021-01-01 12:12:21 +04:00
cli-script.c Update copyright year range in all GDB files 2021-01-01 12:12:21 +04:00
cli-script.h Update copyright year range in all GDB files 2021-01-01 12:12:21 +04:00
cli-setshow.c Update copyright year range in all GDB files 2021-01-01 12:12:21 +04:00
cli-setshow.h Update copyright year range in all GDB files 2021-01-01 12:12:21 +04:00
cli-style.c gdb: add new version style 2021-01-22 19:09:31 +00:00
cli-style.h gdb: add new version style 2021-01-22 19:09:31 +00:00
cli-utils.c Update copyright year range in all GDB files 2021-01-01 12:12:21 +04:00
cli-utils.h Update copyright year range in all GDB files 2021-01-01 12:12:21 +04:00