src: do not run IsWindowsBatchFile on non-windows

PR-URL: https://github.com/nodejs/node/pull/55560
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Stefan Stojanovic <stefan.stojanovic@janeasystems.com>
This commit is contained in:
Yagiz Nizipli authored and RafaelGSS committed 2024-11-01 16:00:13 -03:00
1 parent 3a1d490535
commit 016baaebbe
3 files changed
+16 -16

No files matched your search

+2
View File
@@ -200,8 +200,10 @@ class ProcessWrap : public HandleWrap {
// batch files directly but is potentially insecure because arguments
// are not escaped (and sometimes cannot be unambiguously escaped),
// hence why they are rejected here.
#ifdef _WIN32
if (IsWindowsBatchFile(options.file))
err = UV_EINVAL;
#endif
// options.args
Local<Value> argv_v =
+2
View File
@@ -769,8 +769,10 @@ Maybe<int> SyncProcessRunner::ParseOptions(Local<Value> js_value) {
// batch files directly but is potentially insecure because arguments
// are not escaped (and sometimes cannot be unambiguously escaped),
// hence why they are rejected here.
#ifdef _WIN32
if (IsWindowsBatchFile(uv_process_options_.file))
return Just<int>(UV_EINVAL);
#endif
Local<Value> js_args =
js_options->Get(context, env()->args_string()).ToLocalChecked();
+12 -16
View File
@@ -540,25 +540,21 @@ constexpr std::string_view FastStringKey::as_string_view() const {
// Inline so the compiler can fully optimize it away on Unix platforms.
bool IsWindowsBatchFile(const char* filename) {
#ifdef _WIN32
static constexpr bool kIsWindows = true;
#else
static constexpr bool kIsWindows = false;
#endif // _WIN32
if (kIsWindows) {
std::string file_with_extension = filename;
// Regex to match the last extension part after the last dot, ignoring
// trailing spaces and dots
std::regex extension_regex(R"(\.([a-zA-Z0-9]+)\s*[\.\s]*$)");
std::smatch match;
std::string extension;
std::string file_with_extension = filename;
// Regex to match the last extension part after the last dot, ignoring
// trailing spaces and dots
std::regex extension_regex(R"(\.([a-zA-Z0-9]+)\s*[\.\s]*$)");
std::smatch match;
std::string extension;
if (std::regex_search(file_with_extension, match, extension_regex)) {
extension = ToLower(match[1].str());
}
return !extension.empty() && (extension == "cmd" || extension == "bat");
if (std::regex_search(file_with_extension, match, extension_regex)) {
extension = ToLower(match[1].str());
}
return !extension.empty() && (extension == "cmd" || extension == "bat");
#else
return false;
#endif // _WIN32
}
} // namespace node