Skip to content

Commit 58d6c25

Browse files
committed
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]>
1 parent 3819160 commit 58d6c25

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

winsup/cygwin/dlfcn.cc

+6-4
Original file line numberDiff line numberDiff line change
@@ -426,14 +426,16 @@ dladdr (const void *addr, Dl_info *info)
426426
/* Get the module filename. This pathname may be in short-, long- or //?/
427427
format, depending on how it was specified when loaded, but we assume this
428428
is always an absolute pathname. */
429-
WCHAR fname[MAX_PATH];
430-
DWORD length = GetModuleFileNameW (hModule, fname, MAX_PATH);
431-
if ((length == 0) || (length == MAX_PATH))
429+
tmp_pathbuf tp;
430+
PWCHAR fname = tp.w_get ();
431+
DWORD length = GetModuleFileNameW (hModule, fname, NT_MAX_PATH);
432+
if ((length == 0) || (length == NT_MAX_PATH))
432433
return 0;
433434

434435
/* Convert to a cygwin pathname */
436+
static_assert (sizeof (info->dli_fname) == PATH_MAX);
435437
ssize_t conv = cygwin_conv_path (CCP_WIN_W_TO_POSIX | CCP_ABSOLUTE, fname,
436-
info->dli_fname, MAX_PATH);
438+
info->dli_fname, PATH_MAX);
437439
if (conv)
438440
return 0;
439441

0 commit comments

Comments
 (0)