File tree Expand file tree Collapse file tree 3 files changed +17
-17
lines changed Expand file tree Collapse file tree 3 files changed +17
-17
lines changed Original file line number Diff line number Diff 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 =
Original file line number Diff line number Diff 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 ();
Original file line number Diff line number Diff 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.
541541bool 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
You can’t perform that action at this time.
0 commit comments