[1/3,gdbserver/win32] fatal "glob could not process pattern '(null)'" error

Message ID 1525458603-33351-2-git-send-email-brobecker@adacore.com
State New, archived
Headers

Commit Message

Joel Brobecker May 4, 2018, 6:30 p.m. UTC
  Trying to start GDBserver on Windows currently yields the following
error...

    $ gdbserver.exe --once :4444 simple_main.exe
    glob could not process pattern '(null)'.
    Exiting

... after which GDB terminates with a nonzero status.

This is because create_process in win32-low.c calls gdb_tilde_expand
with the result of a call to get_inferior_cwd without verifying that
the returned directory is not NULL:

    | static BOOL
    | create_process (const char *program, char *args,
    |                 DWORD flags, PROCESS_INFORMATION *pi)
    | {
    |   const char *inferior_cwd = get_inferior_cwd ();
    |   std::string expanded_infcwd = gdb_tilde_expand (inferior_cwd);

This patch avoids this by only calling gdb_tilde_expand when
INFERIOR_CWD is not NULL, which is similar to what is done on
GNU/Linux for instance.

gdb/gdbserver/ChangeLog:

	* win32-low.c (create_process): Only call gdb_tilde_expand if
	inferior_cwd is not NULL.
---
 gdb/gdbserver/win32-low.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
  

Comments

Pedro Alves May 9, 2018, 11:09 p.m. UTC | #1
On 05/04/2018 07:30 PM, Joel Brobecker wrote:
> Trying to start GDBserver on Windows currently yields the following
> error...
> 
>     $ gdbserver.exe --once :4444 simple_main.exe
>     glob could not process pattern '(null)'.
>     Exiting
> 
> ... after which GDB terminates with a nonzero status.
> 
> This is because create_process in win32-low.c calls gdb_tilde_expand
> with the result of a call to get_inferior_cwd without verifying that
> the returned directory is not NULL:
> 
>     | static BOOL
>     | create_process (const char *program, char *args,
>     |                 DWORD flags, PROCESS_INFORMATION *pi)
>     | {
>     |   const char *inferior_cwd = get_inferior_cwd ();
>     |   std::string expanded_infcwd = gdb_tilde_expand (inferior_cwd);
> 
> This patch avoids this by only calling gdb_tilde_expand when
> INFERIOR_CWD is not NULL, which is similar to what is done on
> GNU/Linux for instance.
> 
> gdb/gdbserver/ChangeLog:
> 
> 	* win32-low.c (create_process): Only call gdb_tilde_expand if
> 	inferior_cwd is not NULL.
LGTM.

Thanks,
Pedro Alves
  
Joel Brobecker May 10, 2018, 4:47 p.m. UTC | #2
> > gdb/gdbserver/ChangeLog:
> > 
> > 	* win32-low.c (create_process): Only call gdb_tilde_expand if
> > 	inferior_cwd is not NULL.
> LGTM.

Thanks Pedro. Pushed to master and gdb-8.1-branch, under PR cli/23158.
  

Patch

diff --git a/gdb/gdbserver/win32-low.c b/gdb/gdbserver/win32-low.c
index 9f0c4e4..db5dd49 100644
--- a/gdb/gdbserver/win32-low.c
+++ b/gdb/gdbserver/win32-low.c
@@ -556,7 +556,6 @@  create_process (const char *program, char *args,
 		DWORD flags, PROCESS_INFORMATION *pi)
 {
   const char *inferior_cwd = get_inferior_cwd ();
-  std::string expanded_infcwd = gdb_tilde_expand (inferior_cwd);
   BOOL ret;
 
 #ifdef _WIN32_WCE
@@ -576,6 +575,7 @@  create_process (const char *program, char *args,
 
   if (inferior_cwd != NULL)
     {
+      std::string expanded_infcwd = gdb_tilde_expand (inferior_cwd);
       std::replace (expanded_infcwd.begin (), expanded_infcwd.end (),
 		    '/', '\\');
       wcwd = alloca ((expanded_infcwd.size () + 1) * sizeof (wchar_t));
@@ -607,7 +607,10 @@  Could not convert the expanded inferior cwd to wide-char."));
 			TRUE,     /* inherit handles */
 			flags,    /* start flags */
 			NULL,     /* environment */
-			expanded_infcwd.c_str (), /* current directory */
+			/* current directory */
+			(inferior_cwd == NULL
+			 ? NULL
+			 : gdb_tilde_expand (inferior_cwd).c_str()),
 			&si,      /* start info */
 			pi);      /* proc info */
 #endif