Skip to content

Commit 2b98cc8

Browse files
Jeremy Drake via Cygwin-patchestyan0
authored andcommitted
Cygwin: dladdr: use proper max size of dli_fname.
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: c8432a0 ("Implement dladdr() (partially)") Addresses: rust-lang/backtrace-rs#704 (comment) Signed-off-by: Jeremy Drake <[email protected]> (cherry picked from commit 38772dd)
1 parent 2d529bc commit 2b98cc8

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

winsup/cygwin/dlfcn.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -421,14 +421,16 @@ dladdr (const void *addr, Dl_info *info)
421421
/* Get the module filename. This pathname may be in short-, long- or //?/
422422
format, depending on how it was specified when loaded, but we assume this
423423
is always an absolute pathname. */
424-
WCHAR fname[MAX_PATH];
425-
DWORD length = GetModuleFileNameW (hModule, fname, MAX_PATH);
426-
if ((length == 0) || (length == MAX_PATH))
424+
tmp_pathbuf tp;
425+
PWCHAR fname = tp.w_get ();
426+
DWORD length = GetModuleFileNameW (hModule, fname, NT_MAX_PATH);
427+
if ((length == 0) || (length == NT_MAX_PATH))
427428
return 0;
428429

429430
/* Convert to a cygwin pathname */
431+
static_assert (sizeof (info->dli_fname) == PATH_MAX);
430432
ssize_t conv = cygwin_conv_path (CCP_WIN_W_TO_POSIX | CCP_ABSOLUTE, fname,
431-
info->dli_fname, MAX_PATH);
433+
info->dli_fname, PATH_MAX);
432434
if (conv)
433435
return 0;
434436

0 commit comments

Comments
 (0)