Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: Hannes Domani <ssbssa@yahoo.de>, gdb-patches@sourceware.org
Subject: Re: [PATCH] Fix WOW64 process system DLL paths
Date: Tue, 24 Mar 2020 14:33:26 -0400	[thread overview]
Message-ID: <fb0f24dc-7010-6380-fc4c-fde29a3276d0@simark.ca> (raw)
In-Reply-To: <20200324171734.3335-1-ssbssa@yahoo.de>

On 2020-03-24 1:17 p.m., Hannes Domani via Gdb-patches wrote:
> diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
> index 9c5ea5c046..6f46d3d361 100644
> --- a/gdb/windows-nat.c
> +++ b/gdb/windows-nat.c
> @@ -1993,6 +1993,21 @@ windows_add_all_dlls (void)
>  	return;
>      }
>  
> +#ifdef __x86_64__
> +  char system_dir[__PMAX];
> +  char syswow_dir[__PMAX];
> +  size_t system_dir_len = 0;
> +  size_t syswow_dir_len = 0;
> +  if (wow64_process)
> +    {
> +      GetSystemDirectoryA (system_dir, __PMAX);
> +      GetSystemWow64DirectoryA (syswow_dir, __PMAX);

This functions are documented to possibly fail, so let's check the return value.
If there is not imaginable reason why they would fail, then I using an assertion
is fine.  We should also check that we have passed a large enough buffer.

For example:

  UINT len = GetSystemDirectoryA (system_dir, sizeof (system_dir));

  /* Error check.  */
  gdb_assert (len != 0);

  /* Check that we have passed a large enough buffer.  */
  gdb_assert (len < sizeof (system_dir));


> +      strcat (system_dir, "\\");
> +      strcat (syswow_dir, "\\");
> +      system_dir_len = strlen (system_dir);
> +      syswow_dir_len = strlen (syswow_dir);
> +    }
> +#endif
>    for (i = 1; i < (int) (cb_needed / sizeof (HMODULE)); i++)
>      {
>        MODULEINFO mi;
> @@ -2014,6 +2029,19 @@ windows_add_all_dlls (void)
>  #else
>        name = dll_name;
>  #endif
> +#ifdef __x86_64__
> +      /* Convert the DLL path of WOW64 processes returned by
> +	 GetModuleFileNameEx from the 64bit system directory to the
> +	 32bit syswow64 directory if necessary.  */
> +      if (wow64_process
> +	  && strncasecmp (name, system_dir, system_dir_len) == 0
> +	  && strchr (name + system_dir_len, '\\') == nullptr)
> +	{
> +	  strcpy (syswow_dir + syswow_dir_len, name + system_dir_len);
> +	  strcpy (name, syswow_dir);
> +	  syswow_dir[syswow_dir_len] = 0;
> +	}
> +#endif

Here, I wouldn't mind if you used some std::string a bit more to make
the string less error-prone (even if it involves a bit more copying),
but it's as you wish.

Simon


      reply	other threads:[~2020-03-24 18:33 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20200324171734.3335-1-ssbssa.ref@yahoo.de>
2020-03-24 17:17 ` Hannes Domani
2020-03-24 18:33   ` Simon Marchi [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fb0f24dc-7010-6380-fc4c-fde29a3276d0@simark.ca \
    --to=simark@simark.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=ssbssa@yahoo.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox