Skip to content

Commit 231fe7b

Browse files
anonrigruyadorno
authored andcommitted
src: do not run IsWindowsBatchFile on non-windows
PR-URL: #55560 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Stefan Stojanovic <[email protected]>
1 parent 655e560 commit 231fe7b

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

src/process_wrap.cc

+2
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,10 @@ class ProcessWrap : public HandleWrap {
200200
// batch files directly but is potentially insecure because arguments
201201
// are not escaped (and sometimes cannot be unambiguously escaped),
202202
// hence why they are rejected here.
203+
#ifdef _WIN32
203204
if (IsWindowsBatchFile(options.file))
204205
err = UV_EINVAL;
206+
#endif
205207

206208
// options.args
207209
Local<Value> argv_v =

src/spawn_sync.cc

+2
Original file line numberDiff line numberDiff line change
@@ -769,8 +769,10 @@ Maybe<int> SyncProcessRunner::ParseOptions(Local<Value> js_value) {
769769
// batch files directly but is potentially insecure because arguments
770770
// are not escaped (and sometimes cannot be unambiguously escaped),
771771
// hence why they are rejected here.
772+
#ifdef _WIN32
772773
if (IsWindowsBatchFile(uv_process_options_.file))
773774
return Just<int>(UV_EINVAL);
775+
#endif
774776

775777
Local<Value> js_args =
776778
js_options->Get(context, env()->args_string()).ToLocalChecked();

src/util-inl.h

+13-17
Original file line numberDiff line numberDiff line change
@@ -540,25 +540,21 @@ constexpr std::string_view FastStringKey::as_string_view() const {
540540
// Inline so the compiler can fully optimize it away on Unix platforms.
541541
bool IsWindowsBatchFile(const char* filename) {
542542
#ifdef _WIN32
543-
static constexpr bool kIsWindows = true;
544-
#else
545-
static constexpr bool kIsWindows = false;
546-
#endif // _WIN32
547-
if (kIsWindows) {
548-
std::string file_with_extension = filename;
549-
// Regex to match the last extension part after the last dot, ignoring
550-
// trailing spaces and dots
551-
std::regex extension_regex(R"(\.([a-zA-Z0-9]+)\s*[\.\s]*$)");
552-
std::smatch match;
553-
std::string extension;
554-
555-
if (std::regex_search(file_with_extension, match, extension_regex)) {
556-
extension = ToLower(match[1].str());
557-
}
558-
559-
return !extension.empty() && (extension == "cmd" || extension == "bat");
543+
std::string file_with_extension = filename;
544+
// Regex to match the last extension part after the last dot, ignoring
545+
// trailing spaces and dots
546+
std::regex extension_regex(R"(\.([a-zA-Z0-9]+)\s*[\.\s]*$)");
547+
std::smatch match;
548+
std::string extension;
549+
550+
if (std::regex_search(file_with_extension, match, extension_regex)) {
551+
extension = ToLower(match[1].str());
560552
}
553+
554+
return !extension.empty() && (extension == "cmd" || extension == "bat");
555+
#else
561556
return false;
557+
#endif // _WIN32
562558
}
563559

564560
} // namespace node

0 commit comments

Comments
 (0)