Skip to content

Commit

Permalink
Fix wrong definition of WinNT#KEY_ALL_ACCESS
Browse files Browse the repository at this point in the history
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.

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.
  • Loading branch information
trevormaggs authored and matthiasblaesing committed Aug 23, 2019
1 parent cdad205 commit 8969049
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Bug Fixes
---------
* [#1115](https://github.com/java-native-access/jna/issues/1115): Fix signature for `c.s.j.p.win32.Kernel32#CreateRemoteThread` and bind `VirtualAllocEx`, `VirtualFreeEx`, `GetExitCodeThread` in `c.s.j.p.win32.Kernel32` - [@apangin](https://github.com/apangin), [@matthiasblaesing](https://github.com/matthiasblaesing).
* [#1127](https://github.com/java-native-access/jna/issues/1127): Windows needs a wide string in `c.s.j.p.win32.COM.IShellFolder#ParseDisplayName` - [@dbwiddis](https://github.com/dbwiddis).
* [#1128](https://github.com/java-native-access/jna/issues/1128): KEY_ALL_ACCESS value is incorrect in `c.s.j.p.win32.WinNT.java` - [@trevormaggs](https://github.com/trevormaggs).

Release 5.4.0
=============
Expand Down
4 changes: 2 additions & 2 deletions contrib/platform/src/com/sun/jna/platform/win32/WinNT.java
Original file line number Diff line number Diff line change
Expand Up @@ -919,9 +919,9 @@ public FILE_NOTIFY_INFORMATION next() {

int KEY_EXECUTE = KEY_READ & (~SYNCHRONIZE);

int KEY_ALL_ACCESS = STANDARD_RIGHTS_ALL | KEY_QUERY_VALUE | KEY_SET_VALUE
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);
| KEY_CREATE_LINK) & (~SYNCHRONIZE));

//
// Open/Create Options
Expand Down

0 comments on commit 8969049

Please sign in to comment.