On Wed Jan 29 09:48:53 2025 +0000, Joe Souza wrote:
> After spending some time looking at the existing code, I find that it's
> not that far off from working properly. It correctly allows for
> multiple options to be specified on the command line, and correctly
> handles the exclusive options (i.e. of /N, /E, /S, /D, it correctly
> allows only one of these to take effect). What it gets wrong is that in
> Windows, the first of the exclusive options encountered takes
> precedence, where in current Wine code, it's the last exclusive option
> encountered that takes precedence. Current wine code also does not sort
> directory names for /G.
> All that in mind, the code does not need to be changed to allow multiple
> sort options to be passed to the qsort algorithm. We could clean up the
> use of global variables a bit, sort the directory names for /G, and fix
> the code such that /O by itself is implied /O:NE (which my prior
> proposed change did).
agreed
--
https://gitlab.winehq.org/wine/wine/-/merge_requests/7131#note_93185
Which is use after free since commit 278437b266ed97cebb8e1c14be6cfa2c4f440f07.
Thanks Bernhard Übelacker for spotting this (based on ASan validation).
For a general case I'd say we can have some tests intentionally doing use after free but it is not needed here.
--
https://gitlab.winehq.org/wine/wine/-/merge_requests/7218
This PR updates the behaviour of `NtQueryDirectoryFile`, bringing it in line with current Windows behaviour. The need for this update was discovered when attempting to build the Unreal Engine with MSVC under Wine. In certain cases conditional include statements do not behave as expected, due to MSVC depending on undocumented behaviour of `NtQueryDirectoryFile`.
We ran tests on multiple versions of Windows, and discovered that the behaviour has changed since the original Wine implementation, but the documentation has not. The source code for our test tool, and a set of results can be found [here](https://github.com/TensorWorks/NtQueryDirectoryFile-Test). As of Windows 8, calling `NtQueryDirectoryFile` with a re-used handle, a new mask, and setting the `RestartScan` flag to True, causes the cached results to be erased and a new scan to be performed with the updated mask. Currently, Wine performs as did earlier versions of Windows, where the changed mask is ignored, and the cache is reused. This can cause `NtQueryDirectoryFile` under Wine to falsely report that files exist, when they do not.
This PR corrects this behaviour, invalidating the cache when required. Implementing this exposed further undocumented behaviour of `NtQueryDirectoryFile`, where a search for a non-existent file will return either `STATUS_NO_MORE_FILES` or `STATUS_NO_SUCH_FILE`, depending on whether or not the handle had been previously used regardless of the value of `RestartScan`. This was reflected in a `winetest` which allowed for the response to be either `STATUS_SUCCESS` or `STATUS_NO_MORE_FILES`.
This patch also adds unit tests for the new behaviour of `NtQueryDirectoryFile`. These tests pass when running `winetest` under Windows, and under Wine with these changes in place, but they will fail under older versions of Wine. If run under older versions of Windows the test suite will detect that this functionality is not supported, and will not run the updated tests.
--
v7: ntdll: Update NtQueryDirectoryFile to purge cache if scan is reset with a new mask
ntdll: Test updated NtQueryDirectoryFile mask reset behaviour
https://gitlab.winehq.org/wine/wine/-/merge_requests/6904