diff options
-rw-r--r-- | bfd/version.h | 2 | ||||
-rw-r--r-- | binutils/resbin.c | 5 | ||||
-rw-r--r-- | gdb/Makefile.in | 1 | ||||
-rw-r--r-- | gdb/auto-load.c | 80 | ||||
-rw-r--r-- | gdb/cp-name-parser.y | 8 | ||||
-rw-r--r-- | gdb/unittests/utils-selftests.c | 59 | ||||
-rw-r--r-- | gdb/utils.c | 45 | ||||
-rw-r--r-- | gdb/utils.h | 3 | ||||
-rw-r--r-- | ld/testsuite/ld-plugin/pr25618a.h | 1 | ||||
-rw-r--r-- | ld/testsuite/ld-plugin/pr25618b.h | 1 | ||||
-rw-r--r-- | opcodes/s390-dis.c | 2 |
11 files changed, 85 insertions, 122 deletions
diff --git a/bfd/version.h b/bfd/version.h index a28cdf3..f66dfdc 100644 --- a/bfd/version.h +++ b/bfd/version.h @@ -16,7 +16,7 @@ In releases, the date is not included in either version strings or sonames. */ -#define BFD_VERSION_DATE 20250506 +#define BFD_VERSION_DATE 20250509 #define BFD_VERSION @bfd_version@ #define BFD_VERSION_STRING @bfd_version_package@ @bfd_version_string@ #define REPORT_BUGS_TO @report_bugs_to@ diff --git a/binutils/resbin.c b/binutils/resbin.c index 01046ec..3bce84f 100644 --- a/binutils/resbin.c +++ b/binutils/resbin.c @@ -433,6 +433,11 @@ bin_to_res_menuexitems (windres_bfd *wrbfd, const bfd_byte *data, itemlen = 14 + slen * 2 + 2; itemlen = (itemlen + 3) &~ 3; + /* Don't allow rounding up of itemlen to exceed length. This + is an anti-fuzzer measure to cope with unexpected offsets and + lengths. */ + if (itemlen > length) + itemlen = length; if ((flags & 1) == 0) { diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 77e03e4..285a00b 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -492,7 +492,6 @@ SELFTESTS_SRCS = \ unittests/ui-file-selftests.c \ unittests/unique_xmalloc_ptr_char.c \ unittests/unpack-selftests.c \ - unittests/utils-selftests.c \ unittests/vec-utils-selftests.c \ unittests/xml-utils-selftests.c diff --git a/gdb/auto-load.c b/gdb/auto-load.c index 4fc5b08..f33a8d0 100644 --- a/gdb/auto-load.c +++ b/gdb/auto-load.c @@ -41,6 +41,7 @@ #include <algorithm> #include "gdbsupport/pathstuff.h" #include "cli/cli-style.h" +#include "gdbsupport/selftest.h" /* The section to look in for auto-loaded scripts (in file formats that support sections). @@ -162,6 +163,67 @@ show_auto_load_dir (struct ui_file *file, int from_tty, value); } +/* Substitute all occurrences of string FROM by string TO in STRING. + STRING will be updated in place as needed. FROM needs to be + delimited by IS_DIR_SEPARATOR or DIRNAME_SEPARATOR (or be located + at the start or end of STRING. */ + +static void +substitute_path_component (std::string &string, std::string_view from, + std::string_view to) +{ + for (size_t s = 0;;) + { + s = string.find (from, s); + if (s == std::string::npos) + break; + + if ((s == 0 || IS_DIR_SEPARATOR (string[s - 1]) + || string[s - 1] == DIRNAME_SEPARATOR) + && (s + from.size () == string.size () + || IS_DIR_SEPARATOR (string[s + from.size ()]) + || string[s + from.size ()] == DIRNAME_SEPARATOR)) + { + string.replace (s, from.size (), to); + s += to.size (); + } + else + s++; + } +} + +#if GDB_SELF_TEST + +namespace selftests { +namespace subst_path { + +static void +test_substitute_path_component () +{ + auto test = [] (std::string s, const char *from, const char *to, + const char *expected) + { + substitute_path_component (s, from, to); + SELF_CHECK (s == expected); + }; + + test ("/abc/$def/g", "abc", "xyz", "/xyz/$def/g"); + test ("abc/$def/g", "abc", "xyz", "xyz/$def/g"); + test ("/abc/$def/g", "$def", "xyz", "/abc/xyz/g"); + test ("/abc/$def/g", "g", "xyz", "/abc/$def/xyz"); + test ("/abc/$def/g", "ab", "xyz", "/abc/$def/g"); + test ("/abc/$def/g", "def", "xyz", "/abc/$def/g"); + test ("/abc/$def/g", "abc", "abc", "/abc/$def/g"); + test ("/abc/$def/g", "abc", "", "//$def/g"); + test ("/abc/$def/g", "abc/$def", "xyz", "/xyz/g"); + test ("/abc/$def/abc", "abc", "xyz", "/xyz/$def/xyz"); +} + +} +} + +#endif /* GDB_SELF_TEST */ + /* Directory list safe to hold auto-loaded files. It is not checked for absolute paths but they are strongly recommended. It is initialized by _initialize_auto_load. */ @@ -178,16 +240,15 @@ static std::vector<gdb::unique_xmalloc_ptr<char>> auto_load_safe_path_vec; static std::vector<gdb::unique_xmalloc_ptr<char>> auto_load_expand_dir_vars (const char *string) { - char *s = xstrdup (string); - substitute_path_component (&s, "$datadir", gdb_datadir.c_str ()); - substitute_path_component (&s, "$debugdir", debug_file_directory.c_str ()); + std::string s = string; + substitute_path_component (s, "$datadir", gdb_datadir.c_str ()); + substitute_path_component (s, "$debugdir", debug_file_directory.c_str ()); - if (debug_auto_load && strcmp (s, string) != 0) - auto_load_debug_printf ("Expanded $-variables to \"%s\".", s); + if (debug_auto_load && s != string) + auto_load_debug_printf ("Expanded $-variables to \"%s\".", s.c_str ()); std::vector<gdb::unique_xmalloc_ptr<char>> dir_vec - = dirnames_to_char_ptr_vec (s); - xfree(s); + = dirnames_to_char_ptr_vec (s.c_str ()); return dir_vec; } @@ -1650,4 +1711,9 @@ When non-zero, debugging output for files of 'set auto-load ...'\n\ is displayed."), NULL, show_debug_auto_load, &setdebuglist, &showdebuglist); + +#if GDB_SELF_TEST + selftests::register_test ("substitute_path_component", + selftests::subst_path::test_substitute_path_component); +#endif } diff --git a/gdb/cp-name-parser.y b/gdb/cp-name-parser.y index e7317b7..d4ab98c 100644 --- a/gdb/cp-name-parser.y +++ b/gdb/cp-name-parser.y @@ -2047,9 +2047,11 @@ cp_demangled_name_to_comp (const char *demangled_name, auto result = std::make_unique<demangle_parse_info> (); cpname_state state (demangled_name, result.get ()); - scoped_restore restore_yydebug = make_scoped_restore (&yydebug, - parser_debug); - + /* Note that we can't set yydebug here, as is done in the other + parsers. Bison implements yydebug as a global, even with a pure + parser, and this parser is run from worker threads. So, changing + yydebug causes TSan reports. If you need to debug this parser, + debug gdb and set the global from the outer gdb. */ if (yyparse (&state)) { if (state.global_errmsg && errmsg) diff --git a/gdb/unittests/utils-selftests.c b/gdb/unittests/utils-selftests.c deleted file mode 100644 index b1c457c..0000000 --- a/gdb/unittests/utils-selftests.c +++ /dev/null @@ -1,59 +0,0 @@ -/* Unit tests for the utils.c file. - - Copyright (C) 2018-2025 Free Software Foundation, Inc. - - This file is part of GDB. - - 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 <http://www.gnu.org/licenses/>. */ - -#include "utils.h" -#include "gdbsupport/selftest.h" - -namespace selftests { -namespace utils { - -static void -test_substitute_path_component () -{ - auto test = [] (std::string s, const char *from, const char *to, - const char *expected) - { - char *temp = xstrdup (s.c_str ()); - substitute_path_component (&temp, from, to); - SELF_CHECK (strcmp (temp, expected) == 0); - xfree (temp); - }; - - test ("/abc/$def/g", "abc", "xyz", "/xyz/$def/g"); - test ("abc/$def/g", "abc", "xyz", "xyz/$def/g"); - test ("/abc/$def/g", "$def", "xyz", "/abc/xyz/g"); - test ("/abc/$def/g", "g", "xyz", "/abc/$def/xyz"); - test ("/abc/$def/g", "ab", "xyz", "/abc/$def/g"); - test ("/abc/$def/g", "def", "xyz", "/abc/$def/g"); - test ("/abc/$def/g", "abc", "abc", "/abc/$def/g"); - test ("/abc/$def/g", "abc", "", "//$def/g"); - test ("/abc/$def/g", "abc/$def", "xyz", "/xyz/g"); - test ("/abc/$def/abc", "abc", "xyz", "/xyz/$def/xyz"); -} - -} -} - -void _initialize_utils_selftests (); -void -_initialize_utils_selftests () -{ - selftests::register_test ("substitute_path_component", - selftests::utils::test_substitute_path_component); -} diff --git a/gdb/utils.c b/gdb/utils.c index 6cdc3f4..7b0c812 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -3375,51 +3375,6 @@ parse_pid_to_attach (const char *args) return pid; } -/* Substitute all occurrences of string FROM by string TO in *STRINGP. *STRINGP - must come from xrealloc-compatible allocator and it may be updated. FROM - needs to be delimited by IS_DIR_SEPARATOR or DIRNAME_SEPARATOR (or be - located at the start or end of *STRINGP. */ - -void -substitute_path_component (char **stringp, const char *from, const char *to) -{ - char *string = *stringp, *s; - const size_t from_len = strlen (from); - const size_t to_len = strlen (to); - - for (s = string;;) - { - s = strstr (s, from); - if (s == NULL) - break; - - if ((s == string || IS_DIR_SEPARATOR (s[-1]) - || s[-1] == DIRNAME_SEPARATOR) - && (s[from_len] == '\0' || IS_DIR_SEPARATOR (s[from_len]) - || s[from_len] == DIRNAME_SEPARATOR)) - { - char *string_new; - - string_new - = (char *) xrealloc (string, (strlen (string) + to_len + 1)); - - /* Relocate the current S pointer. */ - s = s - string + string_new; - string = string_new; - - /* Replace from by to. */ - memmove (&s[to_len], &s[from_len], strlen (&s[from_len]) + 1); - memcpy (s, to, to_len); - - s += to_len; - } - else - s++; - } - - *stringp = string; -} - #ifdef HAVE_WAITPID #ifdef SIGALRM diff --git a/gdb/utils.h b/gdb/utils.h index bc8c2ef..a8834cf 100644 --- a/gdb/utils.h +++ b/gdb/utils.h @@ -133,9 +133,6 @@ private: extern int gdb_filename_fnmatch (const char *pattern, const char *string, int flags); -extern void substitute_path_component (char **stringp, const char *from, - const char *to); - std::string ldirname (const char *filename); extern int count_path_elements (const char *path); diff --git a/ld/testsuite/ld-plugin/pr25618a.h b/ld/testsuite/ld-plugin/pr25618a.h index 9bf857c..04be194 100644 --- a/ld/testsuite/ld-plugin/pr25618a.h +++ b/ld/testsuite/ld-plugin/pr25618a.h @@ -1,2 +1 @@ -#pragma once __attribute__((visibility("default"))) int bar(); diff --git a/ld/testsuite/ld-plugin/pr25618b.h b/ld/testsuite/ld-plugin/pr25618b.h index cd80074..65e72a0 100644 --- a/ld/testsuite/ld-plugin/pr25618b.h +++ b/ld/testsuite/ld-plugin/pr25618b.h @@ -1,2 +1 @@ -#pragma once __attribute__((visibility("default"))) int foo(); diff --git a/opcodes/s390-dis.c b/opcodes/s390-dis.c index 9838365..0d32d05 100644 --- a/opcodes/s390-dis.c +++ b/opcodes/s390-dis.c @@ -312,7 +312,7 @@ s390_print_insn_with_opcode (bfd_vma memaddr, info->fprintf_styled_func (info->stream, dis_style_text, "%c", separator); info->fprintf_styled_func (info->stream, dis_style_register, - "%%v%i", val.u); + "%%v%u", val.u); } else if (flags & S390_OPERAND_AR) { |