]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/solib-svr4: check that solib is SVR4 in tls_maybe_fill_slot and tls_maybe_erase_slot
authorSimon Marchi <simon.marchi@efficios.com>
Fri, 23 May 2025 16:30:52 +0000 (12:30 -0400)
committerSimon Marchi <simon.marchi@polymtl.ca>
Sat, 24 May 2025 14:07:42 +0000 (10:07 -0400)
Functions tls_maybe_fill_slot and tls_maybe_erase_slot blindly assume
that the passe solibs come from solib-svr4.  This is not always the
case, because they are called even on the systems where the solib
implementation isn't solib-svr4.  Add some checks to return early in
that case.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32990
Change-Id: I0a281e1f4826aa1914460c2213f0fae1bdc9af7c
Tested-By: Hannes Domani <ssbssa@yahoo.de>
Approved-By: Andrew Burgess <aburgess@redhat.com>
gdb/solib-svr4.c

index 9f56d861354bdcb765a821f1f2f1584a87d46096..a1dc13cb6ff2f817d68bc2bcbb7e5d2e63c3db08 100644 (file)
@@ -1728,6 +1728,10 @@ glibc_link_map_to_tls_module_id (CORE_ADDR lm_addr)
 static void
 tls_maybe_fill_slot (solib &so)
 {
+  auto *li = dynamic_cast<lm_info_svr4 *> (so.lm_info.get ());
+  if (li == nullptr)
+    return;
+
   struct svr4_info *info = get_svr4_info (current_program_space);
   if (!info->glibc_tls_slots_inited)
     {
@@ -1753,7 +1757,6 @@ tls_maybe_fill_slot (solib &so)
       auto it = std::find (info->glibc_tls_slots.begin (),
                           info->glibc_tls_slots.end (),
                           0);
-      auto *li = gdb::checked_static_cast<lm_info_svr4 *> (so.lm_info.get ());
       if (it == info->glibc_tls_slots.end ())
        info->glibc_tls_slots.push_back (li->lm_addr);
       else
@@ -1771,8 +1774,11 @@ tls_maybe_erase_slot (program_space *pspace, const solib &so,
   if (still_in_use)
     return;
 
+  auto *li = dynamic_cast<lm_info_svr4 *> (so.lm_info.get ());
+  if (li == nullptr)
+    return;
+
   struct svr4_info *info = get_svr4_info (pspace);
-  auto *li = gdb::checked_static_cast<lm_info_svr4 *> (so.lm_info.get ());
   auto it = std::find (info->glibc_tls_slots.begin (),
                       info->glibc_tls_slots.end (),
                       li->lm_addr);