Skip to content

Commit

Permalink
Merge pull request #28 from GabrielNagy/fix-high-entropy-aslr-segfault
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Smith <tsmith@chef.io>
  • Loading branch information
tas50 committed Nov 30, 2020
2 parents 516dfbb + cf3e31e commit 9539d2a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
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

0 comments on commit 9539d2a

Please sign in to comment.