File tree Expand file tree Collapse file tree 2 files changed +17
-6
lines changed
Expand file tree Collapse file tree 2 files changed +17
-6
lines changed Original file line number Diff line number Diff line change 2727#include < cmath>
2828#include < cstring>
2929#include < locale>
30+ #include < regex> // NOLINT(build/c++11)
3031#include " node_revert.h"
3132#include " util.h"
3233
@@ -624,10 +625,20 @@ bool IsWindowsBatchFile(const char* filename) {
624625#else
625626 static constexpr bool kIsWindows = false ;
626627#endif // _WIN32
627- if (kIsWindows )
628- if (!IsReverted (SECURITY_REVERT_CVE_2024_27980))
629- if (const char * p = strrchr (filename, ' .' ))
630- return StringEqualNoCase (p, " .bat" ) || StringEqualNoCase (p, " .cmd" );
628+ if (kIsWindows && !IsReverted (SECURITY_REVERT_CVE_2024_27980)) {
629+ std::string file_with_extension = filename;
630+ // Regex to match the last extension part after the last dot, ignoring
631+ // trailing spaces and dots
632+ std::regex extension_regex (R"( \.([a-zA-Z0-9]+)\s*[\.\s]*$)" );
633+ std::smatch match;
634+ std::string extension;
635+
636+ if (std::regex_search (file_with_extension, match, extension_regex)) {
637+ extension = ToLower (match[1 ].str ());
638+ }
639+
640+ return !extension.empty () && (extension == " cmd" || extension == " bat" );
641+ }
631642 return false ;
632643}
633644
Original file line number Diff line number Diff line change @@ -26,8 +26,8 @@ const expectedCode = isWindows && !isRevert ? 'EINVAL' : 'ENOENT';
2626const expectedStatus = isWindows ? 1 : 127 ;
2727
2828const suffixes =
29- 'BAT bAT BaT baT BAt bAt Bat bat CMD cMD CmD cmD CMd cMd Cmd cmd'
30- . split ( ' ' ) ;
29+ 'BAT| bAT| BaT| baT| BAt| bAt| Bat| bat| CMD| cMD| CmD| cmD| CMd| cMd| Cmd|cmd|cmd | cmd .|cmd .... '
30+ . split ( '| ' ) ;
3131
3232if ( process . argv [ 2 ] === undefined ) {
3333 const a = cp . spawnSync ( process . execPath , [ __filename , 'child' ] ) ;
You can’t perform that action at this time.
0 commit comments