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

KEY_ALL_ACCESS value is incorrect in WinNT.java #1128

Closed
trevormaggs opened this issue Aug 20, 2019 · 5 comments
Closed

KEY_ALL_ACCESS value is incorrect in WinNT.java #1128

trevormaggs opened this issue Aug 20, 2019 · 5 comments
Labels

Comments

@trevormaggs
Copy link
Contributor

Version of JNA and related jars
JNA version 5.4.0 - jna-5.4.0.jar and jna-platform-5.4.0.jar

Version and vendor of the java virtual machine
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)

Operating system
Windows 10

System architecture (CPU type, bitness of the JVM)
Xeon X3430 @ 2,40GHz and 64 bit JVM

Complete description of the problem
A bug exists in Line 922 of the WinNT.java source code.

int KEY_ALL_ACCESS = STANDARD_RIGHTS_ALL | KEY_QUERY_VALUE | KEY_SET_VALUE
            | KEY_CREATE_SUB_KEY | KEY_ENUMERATE_SUB_KEYS | KEY_NOTIFY
            | KEY_CREATE_LINK & (~SYNCHRONIZE);

The bitmask value given by the above combination is incorrect due to the missing parentheses. It should match with the original winnt.h C header file in Win32.

 #define KEY_ALL_ACCESS          ((STANDARD_RIGHTS_ALL        |
                                  KEY_QUERY_VALUE            |
                                  KEY_SET_VALUE              |
                                  KEY_CREATE_SUB_KEY         |
                                  KEY_ENUMERATE_SUB_KEYS     |
                                  KEY_NOTIFY                 |
                                  KEY_CREATE_LINK)            
                                  &                           
                                 (~SYNCHRONIZE))

The bug in Java gives an incorrect hex value of 0x1f003f, which should be 0xf003f as confirmed by the C header.

Steps to reproduce

To fix, just add the missing parentheses to exactly match with winnt.h.

       int KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL | 
                KEY_QUERY_VALUE | 
                KEY_SET_VALUE | 
                KEY_CREATE_SUB_KEY | 
                KEY_ENUMERATE_SUB_KEYS | 
                KEY_NOTIFY | 
                KEY_CREATE_LINK) & (~SYNCHRONIZE));

Let me know once the bug fix is resolved and updated in GitHub. Thanks.

Trevor

@dblock
Copy link
Member

dblock commented Aug 20, 2019

Let me know once the bug fix is resolved and updated in GitHub. Thanks.

@trevormaggs Please let us know when you have made a pull request for this.

@dblock dblock added the bug label Aug 20, 2019
@trevormaggs
Copy link
Contributor Author

@dblock. has the bug been fixed? Where is it?

@matthiasblaesing
Copy link
Member

@trevormaggs I think @dblock meant, that you already have the solution, so you could turn that into a PR and propose that for inclusion.

trevormaggs added a commit to trevormaggs/jna that referenced this issue Aug 22, 2019
Please refer to Issue java-native-access#1128 (KEY_ALL_ACCESS value is incorrect in WinNT.java) for details. There is an explanation why it needs to be fixed. 

In short, The KEY_ALL_ACCESS variable has missing parentheses, which gives an incorrect ORed value. It should match with the original winnt.h C header file in Win32.
@trevormaggs
Copy link
Contributor Author

@matthiasblaesing, thanks for your clarification.

@dblock, as requested, please refer to #1129 PR for changes in the code with the proposed bug fix.

@matthiasblaesing
Copy link
Member

Fix was merged to master.

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

No branches or pull requests

3 participants