mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 06:33:01 +00:00
- Extract the correct search pattern and do not interpret '.' or '..'
at the end of the pattern as path (InternalFindFirstFile). svn path=/trunk/; revision=4410
This commit is contained in:
parent
d7d389bf60
commit
52b9204b29
1 changed files with 83 additions and 19 deletions
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: find.c,v 1.34 2003/01/15 21:24:33 chorns Exp $
|
/* $Id: find.c,v 1.35 2003/03/23 10:48:14 hbirr Exp $
|
||||||
*
|
*
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS system libraries
|
* PROJECT: ReactOS system libraries
|
||||||
|
@ -88,34 +88,100 @@ InternalFindFirstFile (
|
||||||
UNICODE_STRING NtPathU;
|
UNICODE_STRING NtPathU;
|
||||||
UNICODE_STRING PatternStr;
|
UNICODE_STRING PatternStr;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
PWSTR End;
|
PWSTR e1, e2;
|
||||||
|
WCHAR CurrentDir[256];
|
||||||
|
PWSTR SearchPath;
|
||||||
|
PWCHAR SearchPattern;
|
||||||
|
ULONG Length;
|
||||||
|
BOOLEAN bResult;
|
||||||
|
|
||||||
DPRINT("FindFirstFileW(lpFileName %S)\n",
|
DPRINT("FindFirstFileW(lpFileName %S)\n",
|
||||||
lpFileName);
|
lpFileName);
|
||||||
|
|
||||||
if (!RtlDosPathNameToNtPathName_U ((LPWSTR)lpFileName,
|
e1 = wcsrchr(lpFileName, L'/');
|
||||||
&NtPathU,
|
e2 = wcsrchr(lpFileName, L'\\');
|
||||||
&End,
|
SearchPattern = max(e1, e2);
|
||||||
NULL))
|
SearchPath = CurrentDir;
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
DPRINT("NtPathU \'%S\' End \'%S\'\n", NtPathU.Buffer, End);
|
if (NULL == SearchPattern)
|
||||||
|
{
|
||||||
|
CHECKPOINT;
|
||||||
|
SearchPattern = (PWCHAR)lpFileName;
|
||||||
|
Length = GetCurrentDirectoryW(sizeof(CurrentDir) / sizeof(WCHAR), SearchPath);
|
||||||
|
if (0 == Length)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (Length > sizeof(CurrentDir) / sizeof(WCHAR))
|
||||||
|
{
|
||||||
|
SearchPath = RtlAllocateHeap(hProcessHeap,
|
||||||
|
HEAP_ZERO_MEMORY,
|
||||||
|
Length * sizeof(WCHAR));
|
||||||
|
if (NULL == SearchPath)
|
||||||
|
{
|
||||||
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
GetCurrentDirectoryW(Length, SearchPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CHECKPOINT;
|
||||||
|
SearchPattern++;
|
||||||
|
Length = SearchPattern - lpFileName;
|
||||||
|
if (Length + 1 > sizeof(CurrentDir) / sizeof(WCHAR))
|
||||||
|
{
|
||||||
|
SearchPath = RtlAllocateHeap(hProcessHeap,
|
||||||
|
HEAP_ZERO_MEMORY,
|
||||||
|
(Length + 1) * sizeof(WCHAR));
|
||||||
|
if (NULL == SearchPath)
|
||||||
|
{
|
||||||
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
memcpy(SearchPath, lpFileName, Length * sizeof(WCHAR));
|
||||||
|
SearchPath[Length] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bResult = RtlDosPathNameToNtPathName_U ((LPWSTR)SearchPath,
|
||||||
|
&NtPathU,
|
||||||
|
NULL,
|
||||||
|
NULL);
|
||||||
|
if (SearchPath != CurrentDir)
|
||||||
|
{
|
||||||
|
RtlFreeHeap(hProcessHeap,
|
||||||
|
0,
|
||||||
|
SearchPath);
|
||||||
|
}
|
||||||
|
if (FALSE == bResult)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
DPRINT("NtPathU \'%S\'\n", NtPathU.Buffer);
|
||||||
|
|
||||||
IData = RtlAllocateHeap (hProcessHeap,
|
IData = RtlAllocateHeap (hProcessHeap,
|
||||||
HEAP_ZERO_MEMORY,
|
HEAP_ZERO_MEMORY,
|
||||||
sizeof(KERNEL32_FIND_FILE_DATA) + FIND_DATA_SIZE);
|
sizeof(KERNEL32_FIND_FILE_DATA) + FIND_DATA_SIZE);
|
||||||
|
if (NULL == IData)
|
||||||
/* move seach pattern to separate string */
|
{
|
||||||
RtlCreateUnicodeString (&PatternStr,
|
RtlFreeHeap (hProcessHeap,
|
||||||
End);
|
0,
|
||||||
*End = 0;
|
NtPathU.Buffer);
|
||||||
NtPathU.Length = wcslen(NtPathU.Buffer)*sizeof(WCHAR);
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* change pattern: "*.*" --> "*" */
|
/* change pattern: "*.*" --> "*" */
|
||||||
if (!wcscmp (PatternStr.Buffer, L"*.*"))
|
if (!wcscmp (SearchPattern, L"*.*"))
|
||||||
{
|
{
|
||||||
PatternStr.Buffer[1] = 0;
|
RtlInitUnicodeStringFromLiteral(&PatternStr, L"*");
|
||||||
PatternStr.Length = sizeof(WCHAR);
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
RtlInitUnicodeString(&PatternStr, SearchPattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
DPRINT("NtPathU \'%S\' Pattern \'%S\'\n",
|
DPRINT("NtPathU \'%S\' Pattern \'%S\'\n",
|
||||||
|
@ -140,7 +206,6 @@ InternalFindFirstFile (
|
||||||
|
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
RtlFreeHeap (hProcessHeap, 0, PatternStr.Buffer);
|
|
||||||
RtlFreeHeap (hProcessHeap, 0, IData);
|
RtlFreeHeap (hProcessHeap, 0, IData);
|
||||||
SetLastErrorByStatus (Status);
|
SetLastErrorByStatus (Status);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
|
@ -159,7 +224,6 @@ InternalFindFirstFile (
|
||||||
TRUE,
|
TRUE,
|
||||||
&PatternStr,
|
&PatternStr,
|
||||||
TRUE);
|
TRUE);
|
||||||
RtlFreeHeap (hProcessHeap, 0, PatternStr.Buffer);
|
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
DPRINT("Status %lx\n", Status);
|
DPRINT("Status %lx\n", Status);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue