From 9283c2ae14f72a7d98551def99c79691f68208b8 Mon Sep 17 00:00:00 2001 From: Guinevere Larsen Date: Wed, 24 Jan 2024 11:17:46 +0100 Subject: [PATCH] backport gdb: fix "list ." related crash This fixes RHBZ 2259850 --- _gdb.spec.Patch.include | 3 + _gdb.spec.patch.include | 1 + _patch_order | 1 + gdb-rhbz2259850-list-period-crash-fix.patch | 101 ++++++++++++++++++++ gdb.spec | 5 +- 5 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 gdb-rhbz2259850-list-period-crash-fix.patch diff --git a/_gdb.spec.Patch.include b/_gdb.spec.Patch.include index f7ee2f4..9bd4ad6 100644 --- a/_gdb.spec.Patch.include +++ b/_gdb.spec.Patch.include @@ -199,3 +199,6 @@ Patch046: gdb-rhbz2257562-cp-namespace-null-ptr-check.patch Patch047: gdb-ftbs-swapped-calloc-args.patch +# Backport gdb: fix "list ." related crash +Patch048: gdb-rhbz2259850-list-period-crash-fix.patch + diff --git a/_gdb.spec.patch.include b/_gdb.spec.patch.include index 8258dc9..ef55dd0 100644 --- a/_gdb.spec.patch.include +++ b/_gdb.spec.patch.include @@ -45,3 +45,4 @@ %patch -p1 -P045 %patch -p1 -P046 %patch -p1 -P047 +%patch -p1 -P048 diff --git a/_patch_order b/_patch_order index ea078f3..c0579d7 100644 --- a/_patch_order +++ b/_patch_order @@ -45,3 +45,4 @@ gdb-rhbz2250652-gdbpy_gil.patch gdb-rhbz2250652-avoid-PyOS_ReadlineTState.patch gdb-rhbz2257562-cp-namespace-null-ptr-check.patch gdb-ftbs-swapped-calloc-args.patch +gdb-rhbz2259850-list-period-crash-fix.patch diff --git a/gdb-rhbz2259850-list-period-crash-fix.patch b/gdb-rhbz2259850-list-period-crash-fix.patch new file mode 100644 index 0000000..0606e66 --- /dev/null +++ b/gdb-rhbz2259850-list-period-crash-fix.patch @@ -0,0 +1,101 @@ +From FEDORA_PATCHES Mon Sep 17 00:00:00 2001 +From: Guinevere Larsen +Date: Mon, 22 Jan 2024 10:13:52 +0100 +Subject: gdb-rhbz2259850-list-period-crash-fix.patch + +;; Backport gdb: fix "list ." related crash + +When a user attempts to use the "list ." command with an inferior that +doesn't have debug symbols, GDB would crash. This was reported as PR +gdb/31256. + +The crash would happen when attempting to get the current symtab_and_line +for the stop location, because the symtab would return a null pointer +and we'd attempt to dereference it to print the line. + +This commit fixes that by checking for an empty symtab and erroring out +of the function if it happens. + +Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31256 +Approved-By: Tom Tromey + +diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c +--- a/gdb/cli/cli-cmds.c ++++ b/gdb/cli/cli-cmds.c +@@ -1291,6 +1291,8 @@ list_command (const char *arg, int from_tty) + set_default_source_symtab_and_line (); + cursal = get_current_source_symtab_and_line (); + } ++ if (cursal.symtab == nullptr) ++ error (_("No debug information available to print source lines.")); + list_around_line (arg, cursal); + /* Set the repeat args so just pressing "enter" after using "list ." + will print the following lines instead of the same lines again. */ +diff --git a/gdb/testsuite/gdb.base/list-nodebug.c b/gdb/testsuite/gdb.base/list-nodebug.c +new file mode 100644 +--- /dev/null ++++ b/gdb/testsuite/gdb.base/list-nodebug.c +@@ -0,0 +1,21 @@ ++/* This testcase is part of GDB, the GNU debugger. ++ ++ Copyright 2024 Free Software Foundation, Inc. ++ ++ This program is free software; you can redistribute it and/or modify ++ it under the terms of the GNU General Public License as published by ++ the Free Software Foundation; either version 3 of the License, or ++ (at your option) any later version. ++ ++ This program is distributed in the hope that it will be useful, ++ but WITHOUT ANY WARRANTY; without even the implied warranty of ++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ GNU General Public License for more details. ++ ++ You should have received a copy of the GNU General Public License ++ along with this program. If not, see . */ ++ ++int main () ++{ ++ return 0; ++} +diff --git a/gdb/testsuite/gdb.base/list-nodebug.exp b/gdb/testsuite/gdb.base/list-nodebug.exp +new file mode 100644 +--- /dev/null ++++ b/gdb/testsuite/gdb.base/list-nodebug.exp +@@ -0,0 +1,37 @@ ++# Copyright 2024 Free Software Foundation, Inc. ++ ++# This program is free software; you can redistribute it and/or modify ++# it under the terms of the GNU General Public License as published by ++# the Free Software Foundation; either version 3 of the License, or ++# (at your option) any later version. ++# ++# This program is distributed in the hope that it will be useful, ++# but WITHOUT ANY WARRANTY; without even the implied warranty of ++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++# GNU General Public License for more details. ++# ++# You should have received a copy of the GNU General Public License ++# along with this program. If not, see . ++ ++# Test that using the command "list" in a file with no debug information ++# will not crash GDB and will give reasonable output. ++ ++standard_testfile .c ++ ++if {[prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \ ++ {nodebug}]} { ++ return -1 ++} ++ ++if {![runto_main]} { ++ untested "couldn't run to main" ++ return ++} ++ ++# Check that GDB doesn't crash when we use list . on an inferior with ++# no debug information ++gdb_test "list ." "No debug.*" "first 'list .'" ++# This should be called twice because the first list invocation since ++# printing a frame may take a different codepath, which wouldn't ++# trigger the crash. ++gdb_test "list ." "No debug.*" "second 'list .'" diff --git a/gdb.spec b/gdb.spec index 3a0250a..b0dc22b 100644 --- a/gdb.spec +++ b/gdb.spec @@ -57,7 +57,7 @@ Version: 14.1 # The release always contains a leading reserved number, start it at 1. # `upstream' is not a part of `name' to stay fully rpm dependencies compatible for the testing. -Release: 6%{?dist} +Release: 7%{?dist} License: GPL-3.0-or-later AND BSD-3-Clause AND FSFAP AND LGPL-2.1-or-later AND GPL-2.0-or-later AND LGPL-2.0-or-later AND LicenseRef-Fedora-Public-Domain AND GFDL-1.3-or-later AND LGPL-2.0-or-later WITH GCC-exception-2.0 AND GPL-3.0-or-later WITH GCC-exception-3.1 AND GPL-2.0-or-later WITH GNU-compiler-exception # Do not provide URL for snapshots as the file lasts there only for 2 days. @@ -1250,6 +1250,9 @@ fi %endif %changelog +* Thu Jan 25 2024 Guinevere Larsen - 14.1-7 +- Backport "gdb: fix list . related crash" + * Wed Jan 24 2024 Fedora Release Engineering - Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild