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

(PUP-7627) Changes CreateSymbolicLinkW return from BOOL to BOOLEAN #5953

Closed
wants to merge 1 commit into from

Conversation

rodjek
Copy link
Contributor

@rodjek rodjek commented Jun 7, 2017

I was tracking down why CreateSymbolicLinkW was returning non-zero when
failing on one test VM and not a different one
(puppetlabs/puppetlabs_spec_helper#192).

Turns out CreateSymbolicLinkW returns a BOOLEAN (1 byte) rather than a
BOOL (4 bytes), so I was getting random garbage in the upper 3 bytes
and therefore a non-zero result.

I was tracking down why CreateSymbolicLinkW was returning non-zero when
failing on one test VM and not a different one
(puppetlabs/puppetlabs_spec_helper#192).

Turns out CreateSymbolicLinkW returns a `BOOLEAN` (1 byte) rather than a
`BOOL` (4 bytes), so I was getting random garbage in the upper 3 bytes
and therefore a non-zero result.
@puppetcla
Copy link

CLA signed by all contributors.

@Iristyle
Copy link
Contributor

Iristyle commented Jun 7, 2017

Great catch @rodjek - thanks! I'm a bit surprised we never ran into this previously.

Can you retarget this at stable? This should go into the next LTS .z

@@ -165,6 +165,9 @@ def read_com_memory_pointer(&block)
# https://blogs.msdn.com/b/oldnewthing/archive/2011/03/28/10146459.aspx
FFI.typedef :int32, :win32_bool

# The BOOLEAN data type (different to BOOL) is only 1 byte.
FFI.typedef :int8, :boolean
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not quite right as the Win32 BYTE is unsigned and the FFI :int8 is signed per https://msdn.microsoft.com/en-us/library/windows/desktop/aa383751%28v=vs.85%29.aspx.

A little further in the file we define :byte (and map it to the FFI :uchar) - so I'd suggest we use that same mapping... https://github.com/ffi/ffi/wiki/Types

FFI.typedef :uchar, :boolean

@Iristyle
Copy link
Contributor

Iristyle commented Jun 7, 2017

Could you also update the signature at https://github.com/puppetlabs/puppet/blob/master/lib/puppet/feature/base.rb#L83 ?

While we never actually call the declared function there, it would still be good to update for consistency.

Thanks again!

@@ -397,7 +397,7 @@ def self.resolve_symlink(handle)
begin
ffi_lib :kernel32
attach_function_private :CreateSymbolicLinkW,
[:lpwstr, :lpwstr, :dword], :win32_bool
[:lpwstr, :lpwstr, :dword], :boolean
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have compared against the only place where we check the result of the call. The docs say returns 0 if failed, which is what we're checking (though we're using the constant WIN32_FALSE which was originally created to compare against BOOL and not BOOLEAN).

That said, I think we're fine with what we've got.

@Iristyle
Copy link
Contributor

Iristyle commented Jun 7, 2017

I fixed the minor issues and retargeted at stable in #5958, so closing this.

Thanks!

@Iristyle Iristyle closed this Jun 7, 2017
@rodjek
Copy link
Contributor Author

rodjek commented Jun 8, 2017

Thanks @Iristyle!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants