diff options
-rw-r--r-- | lib/chef/win32/handle.rb | 5 | ||||
-rw-r--r-- | lib/chef/win32/security.rb | 12 |
2 files changed, 7 insertions, 10 deletions
diff --git a/lib/chef/win32/handle.rb b/lib/chef/win32/handle.rb index 08242375fe..03471f3a86 100644 --- a/lib/chef/win32/handle.rb +++ b/lib/chef/win32/handle.rb @@ -42,10 +42,7 @@ class Chef # to close the pseudo handle returned by the GetCurrentProcess function. The docs also say that it doesn't hurt to call # CloseHandle on it. However, doing so from inside of Ruby always seems to produce an invalid handle error. # The recommendation is to use GetCurrentProcess instead of the const (HANDLE)-1, to ensure we're making the correct comparison. - - # Chef::ReservedNames::Win32::Security.logon_user() creates a token with a handle this is an FFI::Pointer - # and not a valid handle. - return if handle.is_a?(FFI::Pointer) || handle == GetCurrentProcess() + return handle == GetCurrentProcess() unless CloseHandle(handle) Chef::ReservedNames::Win32::Error.raise! diff --git a/lib/chef/win32/security.rb b/lib/chef/win32/security.rb index 01d793b047..acbc1d4c64 100644 --- a/lib/chef/win32/security.rb +++ b/lib/chef/win32/security.rb @@ -722,12 +722,12 @@ class Chef Chef::ReservedNames::Win32::Error.raise! end - # Handle.new(_non handle value_) is not ideal because the finalizer for Handle - # was silently failing when comparing the parameter with the return from - # `GetCurrentProcess()`. In this case, the value is an FFI::Pointer, but the logic - # for Token.new works the same otherwise, so I'm leaving this as is and guarding against - # trying to treat an FFI::Pointer as a Win32 handle in the finalizer. - Token.new(Handle.new(token.read_pointer)) + # originally this was .read_pointer, but that is interpreted as a non-primitive + # class (FFI::Pointer) and causes an ArgumentError (Invalid Memory Object) when + # compared to GetCurrentProcess(), which returns a HANDLE (void *). Since a + # HANDLE is not a pointer to allocated memory that Ruby C extensions can understand, + # the Invalid Memory Object error is raised. + Token.new(Handle.new(token.read_ulong)) end def self.test_and_raise_lsa_nt_status(result) |