Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH 1/1] gdb: Fix null pointer dereference on missing PATH variable
@ 2025-03-04 21:50 Daniel Starke
  2025-03-05  3:38 ` Simon Marchi
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Starke @ 2025-03-04 21:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Daniel Starke

When running "show" with missing PATH variable a null pointer is being
dereferenced in path_info().

path_command() correctly checks whether PATH has been set before using it.
It then calls path_info() which retrieves the variable again but fails to
perform the null pointer test on it. As a result, the application crashes with
SIGSEGV on Windows for example.

Fix this by handling the null pointer case in path_info() accordingly.

Signed-off-by: Daniel Starke <daniel-email@gmx.net>
---
 gdb/infcmd.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 00703e44b7b..adb2592ae8e 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -2116,7 +2116,10 @@ static void
 path_info (const char *args, int from_tty)
 {
   gdb_puts ("Executable and object file path: ");
-  gdb_puts (current_inferior ()->environment.get (path_var_name));
+  const char *env = current_inferior ()->environment.get (path_var_name);
+  if (!env)
+    env = "";
+  gdb_puts (env);
   gdb_puts ("\n");
 }

--
2.39.5


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

end of thread, other threads:[~2025-03-05 16:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-04 21:50 [PATCH 1/1] gdb: Fix null pointer dereference on missing PATH variable Daniel Starke
2025-03-05  3:38 ` Simon Marchi
2025-03-05 15:28   ` Tom Tromey
2025-03-05 15:51     ` Simon Marchi
2025-03-05 16:17   ` daniel-email

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox