Skip to content

windows/security: explicit LOAD_LIBRARY_SEARCH_SYSTEM32 for system32 dll #1717

@jiaz83

Description

@jiaz83

We recently stumpled upon dll loading issues of wtsapi32.dll with prior modification of dll search path via SetDefaultDllDirectories resulting exact same issue as in #1614

calling LoadLibraryEx(relative_path, ..., LOAD_WITH_ALTERED_SEARCH_PATH) results in ERROR_INVALID_PARAMETER.

According to LoadLibraryEx documentation, this results in an undefined behavior when a library name is given as a relative path.
With that in mind, it would be best practise to secure system32 dll loading by using OPTION_OPEN_FLAGS set to LOAD_LIBRARY_SEARCH_SYSTEM32 for those interfaces against system32 dlls.

Map<String, Object> DEFAULT_W32SYSTEM32APIOptions = new HashMap<String, Object>(W32APIOptions.DEFAULT_OPTIONS) {{ //LOAD_LIBRARY_SEARCH_SYSTEM32 put(com.sun.jna.Library.OPTION_OPEN_FLAGS, 0x00000800); }};
Once we switched to LOAD_LIBRARY_SEARCH_SYSTEM32 all system32 dlls in use were properly found/loaded.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions