diff options
author | Brad King <brad.king@kitware.com> | 2023-12-04 19:48:46 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2023-12-04 19:48:46 (GMT) |
commit | b37d9378de961c98785df6a7d2bd3de21f7478b8 (patch) | |
tree | daab2cb6fda684c224abf725a0b41e8d194612a6 /Utilities | |
parent | b9970be9bcadc8f7c45f7603ad6eb1c75620608a (diff) | |
parent | a23da1559648995998343f3ae63076db736b55a5 (diff) | |
download | CMake-b37d9378de961c98785df6a7d2bd3de21f7478b8.zip CMake-b37d9378de961c98785df6a7d2bd3de21f7478b8.tar.gz CMake-b37d9378de961c98785df6a7d2bd3de21f7478b8.tar.bz2 |
libuv: Revert "win/spawn: run executables with no file extension"
This reverts commit da9df7425a (libuv: win/spawn: run executables with
no file extension, 2023-11-29, v3.28.0-rc6~1^2~1). It incorrectly
searched the `PATH` for extension-less command names. Another fix will
be needed for the regression motivating it.
Record this as a merge from the last-imported upstream libuv snapshot
branch so that future `git blame` points to the upstream for the
original code instead of this commit.
Fixes: #25473
Issue: #25450
Diffstat (limited to 'Utilities')
-rw-r--r-- | Utilities/cmlibuv/src/win/process.c | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/Utilities/cmlibuv/src/win/process.c b/Utilities/cmlibuv/src/win/process.c index 02b6c26..9d0ceba 100644 --- a/Utilities/cmlibuv/src/win/process.c +++ b/Utilities/cmlibuv/src/win/process.c @@ -274,16 +274,19 @@ static WCHAR* path_search_walk_ext(const WCHAR *dir, const WCHAR *name, size_t name_len, WCHAR *cwd, - size_t cwd_len) { + size_t cwd_len, + int name_has_ext) { WCHAR* result; - /* Try the name itself first */ - result = search_path_join_test(dir, dir_len, - name, name_len, - L"", 0, - cwd, cwd_len); - if (result != NULL) { - return result; + /* If the name itself has a nonempty extension, try this extension first */ + if (name_has_ext) { + result = search_path_join_test(dir, dir_len, + name, name_len, + L"", 0, + cwd, cwd_len); + if (result != NULL) { + return result; + } } /* Try .com extension */ @@ -326,7 +329,8 @@ static WCHAR* path_search_walk_ext(const WCHAR *dir, * - If there's really only a filename, check the current directory for file, * then search all path directories. * - * - Search for the file exactly as specified first. + * - If filename specified has *any* extension, search for the file with the + * specified extension first. * * - If the literal filename is not found in a directory, try *appending* * (not replacing) .com first and then .exe. @@ -356,8 +360,10 @@ static WCHAR* search_path(const WCHAR *file, int file_has_dir; WCHAR* result = NULL; WCHAR *file_name_start; + WCHAR *dot; const WCHAR *dir_start, *dir_end, *dir_path; size_t dir_len; + int name_has_ext; size_t file_len = wcslen(file); size_t cwd_len = wcslen(cwd); @@ -381,12 +387,17 @@ static WCHAR* search_path(const WCHAR *file, file_has_dir = file_name_start != file; + /* Check if the filename includes an extension */ + dot = wcschr(file_name_start, L'.'); + name_has_ext = (dot != NULL && dot[1] != L'\0'); + if (file_has_dir) { /* The file has a path inside, don't use path */ result = path_search_walk_ext( file, file_name_start - file, file_name_start, file_len - (file_name_start - file), - cwd, cwd_len); + cwd, cwd_len, + name_has_ext); } else { dir_end = path; @@ -395,7 +406,8 @@ static WCHAR* search_path(const WCHAR *file, /* The file is really only a name; look in cwd first, then scan path */ result = path_search_walk_ext(L"", 0, file, file_len, - cwd, cwd_len); + cwd, cwd_len, + name_has_ext); } while (result == NULL) { @@ -444,7 +456,8 @@ static WCHAR* search_path(const WCHAR *file, result = path_search_walk_ext(dir_path, dir_len, file, file_len, - cwd, cwd_len); + cwd, cwd_len, + name_has_ext); } } |