On Wed, 30 Apr 2025 12:45:56 -0700 (PDT)
Jeremy Drake wrote:
> The DL_info::dli_fname member is actually PATH_MAX bytes, so specify
> that (larger) size to cygwin_conv_path rather than MAX_PATH.
> 
> Also, use a tmp_pathbuf for the GetModuleFileNameW buffer, so that any
> buffer size limitation will definitely be due to the size of dli_fname,
> and add a static_assert of the size of dli_fname so we can be sure we're
> using the right size constant here.
> 
> Fixes: c8432a01c840 ("Implement dladdr() (partially)")
> Addresses: 
> https://github.com/rust-lang/backtrace-rs/pull/704#issuecomment-2833782574
> Signed-off-by: Jeremy Drake <cyg...@jdrake.com>
> ---
>  winsup/cygwin/dlfcn.cc | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/winsup/cygwin/dlfcn.cc b/winsup/cygwin/dlfcn.cc
> index 10bd0ac1f4..9b6bb55b34 100644
> --- a/winsup/cygwin/dlfcn.cc
> +++ b/winsup/cygwin/dlfcn.cc
> @@ -421,14 +421,16 @@ dladdr (const void *addr, Dl_info *info)
>    /* Get the module filename.  This pathname may be in short-, long- or //?/
>       format, depending on how it was specified when loaded, but we assume 
> this
>       is always an absolute pathname. */
> -  WCHAR fname[MAX_PATH];
> -  DWORD length = GetModuleFileNameW (hModule, fname, MAX_PATH);
> -  if ((length == 0) || (length == MAX_PATH))
> +  tmp_pathbuf tp;
> +  PWCHAR fname = tp.w_get ();
> +  DWORD length = GetModuleFileNameW (hModule, fname, NT_MAX_PATH);
> +  if ((length == 0) || (length == NT_MAX_PATH))
>      return 0;
> 
>    /* Convert to a cygwin pathname */
> +  static_assert (sizeof (info->dli_fname) == PATH_MAX);
>    ssize_t conv = cygwin_conv_path (CCP_WIN_W_TO_POSIX | CCP_ABSOLUTE, fname,
> -                                info->dli_fname, MAX_PATH);
> +                                info->dli_fname, PATH_MAX);
>    if (conv)
>      return 0;
> 
> -- 
> 2.49.0.windows.1
> 

Thanks for the patch. LGTM. Pushed.

-- 
Takashi Yano <takashi.y...@nifty.ne.jp>

Reply via email to