Skip to content

KEY_ALL_ACCESS value is incorrect in WinNT.java #1128

@trevormaggs

Description

@trevormaggs

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions