mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2025-01-19 14:34:07 +08:00
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.
This commit is contained in:
parent
807f647cac
commit
59b59f08f6
@ -1,3 +1,10 @@
|
||||
2021-01-27 Lancelot SIX <lsix@lancelotsix.com>
|
||||
|
||||
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.
|
||||
|
||||
2021-01-27 Matthew Malcomson <matthew.malcomson@arm.com>
|
||||
|
||||
* aarch64-tdep.c (aarch64_displaced_step_others): Account for
|
||||
|
@ -430,6 +430,14 @@ cli_interp_base::set_logging (ui_file_up logfile, bool logging_redirect,
|
||||
saved_output.file_to_delete = tee;
|
||||
}
|
||||
|
||||
/* Make sure that the call to logfile's dtor does not delete the
|
||||
underlying pointer if we still keep a reference to it. If
|
||||
logfile_p is not referenced as the file_to_delete, then either
|
||||
the logfile is not used (no redirection) and it should be
|
||||
deleted, or a tee took ownership of the pointer. */
|
||||
if (logfile_p != nullptr && saved_output.file_to_delete == logfile_p)
|
||||
logfile.release ();
|
||||
|
||||
gdb_stdout = logging_redirect ? logfile_p : tee;
|
||||
gdb_stdlog = debug_redirect ? logfile_p : tee;
|
||||
gdb_stderr = logging_redirect ? logfile_p : tee;
|
||||
|
@ -1,3 +1,10 @@
|
||||
2021-01-27 Lancelot SIX <lsix@lancelotsix.com>
|
||||
|
||||
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 Matthew Malcomson <matthew.malcomson@arm.com>
|
||||
|
||||
* gdb.arch/insn-reloc.c: Add tests for BR and BLR.
|
||||
|
@ -140,3 +140,11 @@ with_test_prefix "redirect debugging" {
|
||||
gdb_test "set logging off" "Done logging to /dev/null\\."
|
||||
gdb_test "help" "List of classes of commands:.*"
|
||||
}
|
||||
|
||||
with_test_prefix "redirect logging and debuging" {
|
||||
gdb_test_no_output "set logging redirect on"
|
||||
gdb_test_no_output "set logging debugredirect on"
|
||||
gdb_test "set logging on" \
|
||||
"Redirecting output to /dev/null.*Redirecting debug output to /dev/null\\."
|
||||
gdb_test "set logging off" "Done logging to /dev/null\\."
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user