From 298935287942f62fd60a8b5ded64ed9ca6df3715 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9=20van=20Geldorp?= Date: Tue, 9 Dec 2003 23:37:59 +0000 Subject: [PATCH] Handle \path\ending\in\slash\ directory searches svn path=/trunk/; revision=6942 --- reactos/lib/kernel32/file/find.c | 79 ++++++++++++++++++++++++++++---- 1 file changed, 71 insertions(+), 8 deletions(-) diff --git a/reactos/lib/kernel32/file/find.c b/reactos/lib/kernel32/file/find.c index 17851fc4dc8..0e9a3272cdc 100644 --- a/reactos/lib/kernel32/file/find.c +++ b/reactos/lib/kernel32/file/find.c @@ -1,4 +1,4 @@ -/* $Id: find.c,v 1.40 2003/11/17 02:12:50 hyperion Exp $ +/* $Id: find.c,v 1.41 2003/12/09 23:37:59 gvg Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries @@ -96,6 +96,7 @@ InternalFindFirstFile ( NTSTATUS Status; PWSTR e1, e2; WCHAR CurrentDir[256]; + PWCHAR SlashlessFileName; PWSTR SearchPath; PWCHAR SearchPattern; ULONG Length; @@ -104,6 +105,26 @@ InternalFindFirstFile ( DPRINT("FindFirstFileW(lpFileName %S)\n", lpFileName); + Length = wcslen(lpFileName); + if (L'\\' == lpFileName[Length - 1]) + { + SlashlessFileName = RtlAllocateHeap(hProcessHeap, + 0, + Length * sizeof(WCHAR)); + if (NULL == SlashlessFileName) + { + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return NULL; + } + memcpy(SlashlessFileName, lpFileName, (Length - 1) * sizeof(WCHAR)); + SlashlessFileName[Length - 1] = L'\0'; + lpFileName = SlashlessFileName; + } + else + { + SlashlessFileName = NULL; + } + e1 = wcsrchr(lpFileName, L'/'); e2 = wcsrchr(lpFileName, L'\\'); SearchPattern = max(e1, e2); @@ -116,6 +137,12 @@ InternalFindFirstFile ( Length = GetCurrentDirectoryW(sizeof(CurrentDir) / sizeof(WCHAR), SearchPath); if (0 == Length) { + if (NULL != SlashlessFileName) + { + RtlFreeHeap(hProcessHeap, + 0, + SlashlessFileName); + } return NULL; } if (Length > sizeof(CurrentDir) / sizeof(WCHAR)) @@ -125,6 +152,12 @@ InternalFindFirstFile ( Length * sizeof(WCHAR)); if (NULL == SearchPath) { + if (NULL != SlashlessFileName) + { + RtlFreeHeap(hProcessHeap, + 0, + SlashlessFileName); + } SetLastError(ERROR_NOT_ENOUGH_MEMORY); return NULL; } @@ -143,6 +176,12 @@ InternalFindFirstFile ( (Length + 1) * sizeof(WCHAR)); if (NULL == SearchPath) { + if (NULL != SlashlessFileName) + { + RtlFreeHeap(hProcessHeap, + 0, + SlashlessFileName); + } SetLastError(ERROR_NOT_ENOUGH_MEMORY); return NULL; } @@ -163,6 +202,12 @@ InternalFindFirstFile ( } if (FALSE == bResult) { + if (NULL != SlashlessFileName) + { + RtlFreeHeap(hProcessHeap, + 0, + SlashlessFileName); + } return NULL; } @@ -176,6 +221,12 @@ InternalFindFirstFile ( RtlFreeHeap (hProcessHeap, 0, NtPathU.Buffer); + if (NULL != SlashlessFileName) + { + RtlFreeHeap(hProcessHeap, + 0, + SlashlessFileName); + } SetLastError(ERROR_NOT_ENOUGH_MEMORY); return NULL; } @@ -212,9 +263,15 @@ InternalFindFirstFile ( if (!NT_SUCCESS(Status)) { - RtlFreeHeap (hProcessHeap, 0, IData); - SetLastErrorByStatus (Status); - return(NULL); + RtlFreeHeap (hProcessHeap, 0, IData); + if (NULL != SlashlessFileName) + { + RtlFreeHeap(hProcessHeap, + 0, + SlashlessFileName); + } + SetLastErrorByStatus (Status); + return(NULL); } IData->pFileInfo = (PVOID)IData + sizeof(KERNEL32_FIND_FILE_DATA); IData->pFileInfo->FileIndex = 0; @@ -230,12 +287,18 @@ InternalFindFirstFile ( TRUE, &PatternStr, TRUE); + if (NULL != SlashlessFileName) + { + RtlFreeHeap(hProcessHeap, + 0, + SlashlessFileName); + } if (!NT_SUCCESS(Status)) { - DPRINT("Status %lx\n", Status); - RtlFreeHeap (hProcessHeap, 0, IData); - SetLastErrorByStatus (Status); - return NULL; + DPRINT("Status %lx\n", Status); + RtlFreeHeap (hProcessHeap, 0, IData); + SetLastErrorByStatus (Status); + return NULL; } DPRINT("Found %.*S\n",IData->pFileInfo->FileNameLength/sizeof(WCHAR), IData->pFileInfo->FileName);