GeezerVison is showing github.com — src: do not run IsWindowsBatchFile on non-windows · nodejs/node@016baae
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/process_wrap.cc +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -200,8 +200,10 @@ class ProcessWrap : public HandleWrap { |
200 | 200 | // batch files directly but is potentially insecure because arguments |
201 | 201 | // are not escaped (and sometimes cannot be unambiguously escaped), |
202 | 202 | // hence why they are rejected here. |
| 203 | +#ifdef _WIN32 |
203 | 204 | if (IsWindowsBatchFile(options.file)) |
204 | 205 | err = UV_EINVAL; |
| 206 | +#endif |
205 | 207 |
|
206 | 208 | // options.args |
207 | 209 | Local<Value> argv_v = |
|
Collapse file
Copy file name to clipboardExpand all lines: src/spawn_sync.cc +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -769,8 +769,10 @@ Maybe<int> SyncProcessRunner::ParseOptions(Local<Value> js_value) { |
769 | 769 | // batch files directly but is potentially insecure because arguments |
770 | 770 | // are not escaped (and sometimes cannot be unambiguously escaped), |
771 | 771 | // hence why they are rejected here. |
| 772 | +#ifdef _WIN32 |
772 | 773 | if (IsWindowsBatchFile(uv_process_options_.file)) |
773 | 774 | return Just<int>(UV_EINVAL); |
| 775 | +#endif |
774 | 776 |
|
775 | 777 | Local<Value> js_args = |
776 | 778 | js_options->Get(context, env()->args_string()).ToLocalChecked(); |
|
Collapse file
Copy file name to clipboardExpand all lines: src/util-inl.h +13-17Lines changed: 13 additions & 17 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -540,25 +540,21 @@ constexpr std::string_view FastStringKey::as_string_view() const { |
540 | 540 | // Inline so the compiler can fully optimize it away on Unix platforms. |
541 | 541 | bool IsWindowsBatchFile(const char* filename) { |
542 | 542 | #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()); |
560 | 552 | } |
| 553 | + |
| 554 | + return !extension.empty() && (extension == "cmd" || extension == "bat"); |
| 555 | +#else |
561 | 556 | return false; |
| 557 | +#endif // _WIN32 |
562 | 558 | } |
563 | 559 |
|
564 | 560 | } // namespace node |
|