From e283a286894dae2af87a66c1fc2620dfce27d93d Mon Sep 17 00:00:00 2001 From: Daniel Starke Date: Tue, 4 Mar 2025 22:50:11 +0100 Subject: [PATCH] gdb: fix null pointer dereference on missing PATH variable 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 Co-Authored-By: Simon Marchi Approved-By: Tom Tromey Change-Id: I41ef10f00802d3163793491454190008e78f5dc1 --- gdb/infcmd.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/gdb/infcmd.c b/gdb/infcmd.c index 00703e44b7b..74e1e26327b 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -2115,9 +2115,10 @@ static const char path_var_name[] = "PATH"; 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)); - gdb_puts ("\n"); + const char *env = current_inferior ()->environment.get (path_var_name); + + gdb_printf (_("Executable and object file path: %s\n"), + env != nullptr ? env : ""); } /* Add zero or more directories to the front of the execution path. */ -- 2.39.5