kernel32: add test for FindFirstFileA with a path ending with "/>"
Vincent Pelletier
plr.vincent at gmail.com
Fri Apr 1 17:14:43 CDT 2011
Fixes bug 22635.
---
dlls/kernel32/tests/file.c | 119
++++++++++++++++++++++++++++++++++++++++++++
dlls/ntdll/path.c | 8 +++-
2 files changed, 126 insertions(+), 1 deletions(-)
diff --git a/dlls/kernel32/tests/file.c b/dlls/kernel32/tests/file.c
index 4e8136a..dae8eee 100644
--- a/dlls/kernel32/tests/file.c
+++ b/dlls/kernel32/tests/file.c
@@ -2164,6 +2164,125 @@ static void test_FindFirstFileA(void)
err = GetLastError();
ok ( handle == INVALID_HANDLE_VALUE, "FindFirstFile on %s should Fail\n",
buffer2 );
ok ( err == ERROR_PATH_NOT_FOUND, "Bad Error number %d\n", err );
+
+ /* try FindFirstFileA on "test-dir" with forbidden chars */
+ CreateDirectoryA("test-dir", NULL);
+ _lclose(_lcreat("test-file", 0));
+
+#define FindFirstFileA_ok(value, caption, todo) { \
+ if(todo) { \
+ todo_wine ok(value, caption);\
+ } else { \
+ ok(value, caption);\
+ } \
+ }
+
+#define test_FindFirstFileA_with(x, y, todo) { \
+ handle = FindFirstFileA(x, &data);\
+ if (y) { \
+ FindFirstFileA_ok( \
+ handle != INVALID_HANDLE_VALUE, \
+ "FindFirstFile on "x" should succeed\n", \
+ todo);\
+ } else { \
+ FindFirstFileA_ok( \
+ handle == INVALID_HANDLE_VALUE, \
+ "FindFirstFile on "x" should fail\n", \
+ todo);\
+ } \
+ if (handle != INVALID_HANDLE_VALUE) \
+ ok( FindClose(handle) == TRUE, "Failed to close handle "x"\n");
\
+ }
+
+ /* Disallowed chars being ignored: */
+ test_FindFirstFileA_with("test-dir/.", 1, 0);
+ test_FindFirstFileA_with("test-dir\\.", 1, 0);
+ test_FindFirstFileA_with("test-dir<.", 1, 0);
+ test_FindFirstFileA_with("test-dir< ", 1, 0);
+ test_FindFirstFileA_with("test-dir>.", 1, 0);
+ test_FindFirstFileA_with("test-dir> ", 1, 0);
+ test_FindFirstFileA_with("test-dir\".", 1, 0);
+ test_FindFirstFileA_with("test-dir\" ", 1, 0);
+ test_FindFirstFileA_with("test-dir/>", 1, 0);
+ test_FindFirstFileA_with("test-dir/<", 1, 0);
+ test_FindFirstFileA_with("test-dir/\"", 1, 0);
+ test_FindFirstFileA_with("test-dir<>", 1, 0);
+ test_FindFirstFileA_with("test-dir<<", 1, 0);
+ test_FindFirstFileA_with("test-dir<\"", 1, 0);
+ test_FindFirstFileA_with("test-dir>>", 1, 0);
+ test_FindFirstFileA_with("test-dir><", 1, 0);
+ test_FindFirstFileA_with("test-dir>\"", 1, 0);
+ test_FindFirstFileA_with("test-dir\">", 1, 0);
+ test_FindFirstFileA_with("test-dir\"<", 1, 0);
+ test_FindFirstFileA_with("test-dir\"\"", 1, 0);
+ test_FindFirstFileA_with("test-dir\\<", 1, 0);
+ test_FindFirstFileA_with("test-dir\\>", 1, 0);
+ test_FindFirstFileA_with("test-dir\\\"", 1, 0);
+ /* But space prevents forward & back slashes from being stripped */
+ test_FindFirstFileA_with("test-dir <", 0, 1);
+ test_FindFirstFileA_with("test-dir/ ", 0, 0);
+ test_FindFirstFileA_with("test-dir/ .", 0, 0);
+ test_FindFirstFileA_with("test-dir/. ", 0, 1);
+ test_FindFirstFileA_with("test-dir\\ ", 0, 0);
+ test_FindFirstFileA_with("test-dir\\ .", 0, 0);
+ test_FindFirstFileA_with("test-dir\\. ", 0, 1);
+ test_FindFirstFileA_with("test-dir/. ", 0, 1);
+ test_FindFirstFileA_with("test-dir\\. ", 0, 1);
+ /* But forward & back slashes are not tolerated on a file */
+ test_FindFirstFileA_with("test-file/>", 0, 1);
+ test_FindFirstFileA_with("test-file/<", 0, 1);
+ test_FindFirstFileA_with("test-file/\"", 0, 1);
+ test_FindFirstFileA_with("test-file<>", 1, 0);
+ test_FindFirstFileA_with("test-file<<", 1, 0);
+ test_FindFirstFileA_with("test-file<\"", 1, 0);
+ test_FindFirstFileA_with("test-file>>", 1, 0);
+ test_FindFirstFileA_with("test-file><", 1, 0);
+ test_FindFirstFileA_with("test-file>\"", 1, 0);
+ test_FindFirstFileA_with("test-file\">", 1, 0);
+ test_FindFirstFileA_with("test-file\"<", 1, 0);
+ test_FindFirstFileA_with("test-file\"\"", 1, 0);
+ test_FindFirstFileA_with("test-file\\<", 0, 1);
+ test_FindFirstFileA_with("test-file\\>", 0, 1);
+ test_FindFirstFileA_with("test-file\\\"", 0, 1);
+ /* Even when many */
+ test_FindFirstFileA_with("test-dir\"\"\"\"\"", 1, 0);
+ test_FindFirstFileA_with("test-dir<<<><><>\"\"\"\"<<<>", 1, 0);
+ /* But only in the end of path */
+ test_FindFirstFileA_with("test-/>dir", 0, 0);
+ test_FindFirstFileA_with("/>test-dir", 0, 0);
+ test_FindFirstFileA_with(">test-dir", 0, 0);
+ test_FindFirstFileA_with(">>test-dir", 0, 0);
+ test_FindFirstFileA_with(">test->dir", 0, 0);
+ test_FindFirstFileA_with("><test->dir", 0, 0);
+ test_FindFirstFileA_with("<test->dir", 0, 0);
+ test_FindFirstFileA_with("<\"test->dir", 0, 0);
+
+ /* Slash after ignored chars is not ignored: */
+ test_FindFirstFileA_with("test-dir//", 0, 0);
+ test_FindFirstFileA_with("test-dir</", 0, 0);
+ test_FindFirstFileA_with("test-dir>/", 0, 0);
+ test_FindFirstFileA_with("test-dir\"/", 0, 0);
+ test_FindFirstFileA_with("test-dir\\", 0, 0);
+ test_FindFirstFileA_with("test-dir\\\\", 0, 0);
+ test_FindFirstFileA_with("test-dir\\/", 0, 0);
+ test_FindFirstFileA_with("test-dir/\\", 0, 0);
+
+ /* Disalowed chars being preserved: */
+ test_FindFirstFileA_with("test-dir/:", 0, 0);
+ test_FindFirstFileA_with("test-dir/|", 0, 0);
+
+ /* Slashes converted to backslashes */
+ test_FindFirstFileA_with("test-dir/", 0, 0);
+ test_FindFirstFileA_with("./test-dir", 1, 0);
+ test_FindFirstFileA_with("./test-dir/", 0, 0);
+ test_FindFirstFileA_with("test-dir\\", 0, 0);
+ test_FindFirstFileA_with(".\\test-dir", 1, 0);
+ test_FindFirstFileA_with(".\\test-dir\\", 0, 0);
+
+#undef test_FindFirstFileA_with
+#undef FindFirstFileA_ok
+ DeleteFileA("test-file");
+ RemoveDirectoryA("test-dir");
}
static void test_FindNextFileA(void)
diff --git a/dlls/ntdll/path.c b/dlls/ntdll/path.c
index 3207720..61a1f86 100644
--- a/dlls/ntdll/path.c
+++ b/dlls/ntdll/path.c
@@ -499,6 +499,7 @@ ULONG WINAPI RtlDosSearchPath_U(LPCWSTR paths, LPCWSTR
search, LPCWSTR ext,
static inline void collapse_path( WCHAR *path, UINT mark )
{
WCHAR *p, *next;
+ int stripped = 0;
/* convert every / into a \ */
for (p = path; *p; p++) if (*p == '/') *p = '\\';
@@ -560,7 +561,12 @@ static inline void collapse_path( WCHAR *path, UINT mark
)
}
/* remove trailing spaces and dots (yes, Windows really does that, don't
ask) */
- while (p > path + mark && (p[-1] == ' ' || p[-1] == '.')) p--;
+ while (p > path + mark && (p[-1] == ' ' || p[-1] == '.' || p[-1] == '>'
|| p[-1] == '<' || p[-1] == '"')) {
+ stripped = p[-1] != ' ';
+ p--;
+ }
+
+ if (stripped && p[-1] == '\\') p--;
*p = 0;
}
--
1.7.4.1
More information about the wine-patches
mailing list