Skip to content

Commit 49f63eb

Browse files
author
Kai Luo
committed
Check data segment range
1 parent 82bfdc8 commit 49f63eb

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

compiler/rustc_session/src/filesearch.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,8 @@ fn current_dll_path() -> Result<PathBuf, String> {
8989
// * The address of the entry point of the function.
9090
// * The TOC base address for the function.
9191
// * The environment pointer.
92-
// Deref `current_dll_path` directly so that we can get the address of `current_dll_path`'s
93-
// entry point in text section.
94-
let addr = *(current_dll_path as *const u64);
92+
// The function descriptor is in the data section.
93+
let addr = current_dll_path as u64;
9594
let mut buffer = vec![std::mem::zeroed::<libc::ld_info>(); 64];
9695
loop {
9796
if libc::loadquery(
@@ -110,9 +109,9 @@ fn current_dll_path() -> Result<PathBuf, String> {
110109
}
111110
let mut current = buffer.as_mut_ptr() as *mut libc::ld_info;
112111
loop {
113-
let text_base = (*current).ldinfo_textorg as u64;
114-
let text_end = text_base + (*current).ldinfo_textsize;
115-
if (text_base..text_end).contains(&addr) {
112+
let data_base = (*current).ldinfo_dataorg as u64;
113+
let data_end = data_base + (*current).ldinfo_datasize;
114+
if (data_base..data_end).contains(&addr) {
116115
let bytes = CStr::from_ptr(&(*current).ldinfo_filename[0]).to_bytes();
117116
let os = OsStr::from_bytes(bytes);
118117
return Ok(PathBuf::from(os));

0 commit comments

Comments
 (0)