wine-staging/patches/kernel32-FindFirstFile/0001-kernel32-Strip-invalid-characters-from-mask-in-FindF.patch

73 lines
2.4 KiB
Diff
Raw Normal View History

From 339d3f797f4ba20feac9c887dc79734cd15a2c10 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michael=20M=C3=BCller?= <michael@fds-team.de>
Date: Sat, 6 Feb 2016 18:31:25 +0100
Subject: [PATCH] kernel32: Strip invalid characters from mask in
FindFirstFileExW.
---
dlls/kernelbase/file.c | 26 ++++++++++++++++++++++----
1 file changed, 22 insertions(+), 4 deletions(-)
diff --git a/dlls/kernelbase/file.c b/dlls/kernelbase/file.c
index 89c5f85cb20..542531e895c 100644
--- a/dlls/kernelbase/file.c
+++ b/dlls/kernelbase/file.c
@@ -795,6 +795,7 @@ HANDLE WINAPI DECLSPEC_HOTPATCH FindFirstFileExW( LPCWSTR filename, FINDEX_INFO_
WCHAR *mask;
BOOL has_wildcard = FALSE;
FIND_FIRST_INFO *info = NULL;
+ UNICODE_STRING mask_str;
UNICODE_STRING nt_name;
OBJECT_ATTRIBUTES attr;
IO_STATUS_BLOCK io;
@@ -826,6 +827,8 @@ HANDLE WINAPI DECLSPEC_HOTPATCH FindFirstFileExW( LPCWSTR filename, FINDEX_INFO_
return INVALID_HANDLE_VALUE;
}
+ RtlInitUnicodeString( &mask_str, NULL );
+
if (!mask && (device = RtlIsDosDeviceName_U( filename )))
{
static const WCHAR dotW[] = {'.',0};
@@ -860,8 +863,26 @@ HANDLE WINAPI DECLSPEC_HOTPATCH FindFirstFileExW( LPCWSTR filename, FINDEX_INFO_
}
else
{
+ static const WCHAR invalidW[] = { '<', '>', '\"', 0 };
+ DWORD mask_len = lstrlenW( mask );
+
+ /* strip invalid characters from mask */
+ while (mask_len && wcschr( invalidW, mask[mask_len - 1] ))
+ mask_len--;
+
+ if (!mask_len)
+ {
+ has_wildcard = TRUE;
+ RtlInitUnicodeString( &mask_str, L"*?" );
+ }
+ else
+ {
+ has_wildcard = wcspbrk( mask, L"*?" ) != NULL;
+ RtlInitUnicodeString( &mask_str, mask );
+ mask_str.Length = mask_len * sizeof(WCHAR);
+ }
+
nt_name.Length = (mask - nt_name.Buffer) * sizeof(WCHAR);
- has_wildcard = wcspbrk( mask, L"*?" ) != NULL;
size = has_wildcard ? 8192 : max_entry_size;
}
@@ -922,9 +943,6 @@ HANDLE WINAPI DECLSPEC_HOTPATCH FindFirstFileExW( LPCWSTR filename, FINDEX_INFO_
}
else
{
- UNICODE_STRING mask_str;
-
- RtlInitUnicodeString( &mask_str, mask );
status = NtQueryDirectoryFile( info->handle, 0, NULL, NULL, &io, info->data, info->data_size,
FileBothDirectoryInformation, FALSE, &mask_str, TRUE );
if (status)
--
2.17.1