public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb/solib-svr4.c: Fix segfault caused by NULL pointer
@ 2022-03-04 10:54 Mikael Szreder
  2022-03-04 12:35 ` Bruno Larsen
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Mikael Szreder @ 2022-03-04 10:54 UTC (permalink / raw)
  To: gdb-patches

Inside the function 'enable_break' there is a call to 'find_program_interpreter'.
This function returns an empty vector when an ELF file does not contain
an interpreter because the function 'read_program_header' header
returns an empty vector on failure.

The call to 'interp_name_holder->data()' then returns NULL for an empty vector.
This causes a segmentation fault down the line.
---
 gdb/solib-svr4.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index 69f2991f5e6..18bd712e061 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -2204,7 +2204,7 @@ enable_break (struct svr4_info *info, int from_tty)
      into the old breakpoint at symbol code.  */
   gdb::optional<gdb::byte_vector> interp_name_holder
     = find_program_interpreter ();
-  if (interp_name_holder)
+  if (interp_name_holder && interp_name_holder->size() != 0)
     {
       const char *interp_name = (const char *) interp_name_holder->data ();
       CORE_ADDR load_addr = 0;
-- 
2.35.1

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-03-04 16:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-04 10:54 [PATCH] gdb/solib-svr4.c: Fix segfault caused by NULL pointer Mikael Szreder
2022-03-04 12:35 ` Bruno Larsen
2022-03-04 14:35 ` Tom Tromey
2022-03-04 16:13 ` Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).