Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix segfault if high-entropy 64-bit ASLR is enabled #28

Merged
merged 1 commit into from
Nov 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/win32/dir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,19 @@ class Dir
elsif SHGetFolderPathW(0, value, 0, 1, buf) == 0 # Default path
path = buf.strip
else
ptr = FFI::MemoryPointer.new(:long)
ptr = FFI::MemoryPointer.new(:uint64)
info = SHFILEINFO.new
flags = SHGFI_DISPLAYNAME | SHGFI_PIDL

if SHGetFolderLocation(0, value, 0, 0, ptr) == 0
if SHGetFileInfo(ptr.read_long, 0, info, info.size, flags) != 0
# Use read_array_of_uint64 for compatibility with JRuby if necessary.
if ptr.respond_to?(:read_uint64)
res = SHGetFileInfo(ptr.read_uint64, 0, info, info.size, flags)
else
res = SHGetFileInfo(ptr.read_array_of_uint64(1).first, 0, info, info.size, flags)
end

if res != 0
path = info[:szDisplayName].to_s
path.force_encoding(Encoding.default_external)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/win32/dir/functions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def attach_pfunc(*args)

attach_pfunc :SHGetFolderPathW, %i{hwnd int handle dword buffer_out}, :dword
attach_pfunc :SHGetFolderLocation, %i{hwnd int handle dword ptr}, :dword
attach_pfunc :SHGetFileInfo, %i{dword dword ptr uint uint}, :dword
attach_pfunc :SHGetFileInfo, %i{uint64 dword ptr uint uint}, :dword

ffi_lib :shlwapi
ffi_convention :stdcall
Expand Down