@@ -219,17 +219,6 @@ const TIMEOUT_VALUE_FLAGS = new Set(['-k', '-s', '--kill-after', '--signal']);
219219// is checked while `bait` is still the original directory.
220220const PATH_RELINKING_PROGRAMS = new Set ( [ 'cp' , 'ln' , 'mv' ] ) ;
221221
222- // The cmd.exe spellings of the same capability (`mklink` also covers
223- // junctions/hardlinks, which point a name at another volume entirely).
224- const WIN32_PATH_RELINKING_PROGRAMS = new Set ( [
225- ...PATH_RELINKING_PROGRAMS ,
226- 'copy' ,
227- 'mklink' ,
228- 'move' ,
229- 'robocopy' ,
230- 'xcopy' ,
231- ] ) ;
232-
233222// Archive extractors do not name the paths they write: the archive decides.
234223// Everything under their extraction directory is therefore suspect, which is
235224// the directory itself rather than any operand.
@@ -813,9 +802,9 @@ const GIT_WORD_PATTERN = /\bgit\b/i;
813802// A `cd`/`pushd` inside such a payload relocates the git that follows it just
814803// as effectively as a `-C` flag (`su -c 'cd <outside> && git reset --hard'`).
815804const TEXT_RELOCATION_MARKER_WITHOUT_C_PATTERN =
816- / ( ^ | \s ) ( - - g i t - d i r = ? | - - w o r k - t r e e = ? | - e x e c d i r ) | ( ^ | [ \s ; & | ( ) { } ] ) ( c d | c h d i r | p u s h d ) ( [ \s ; & | ] | $ ) | ( ^ | [ \s ; & | ( ) { } ] ) ( G I T _ D I R | G I T _ W O R K _ T R E E | G I T _ C O M M O N _ D I R | G I T _ I N D E X _ F I L E | G I T _ E X E C _ P A T H | P A T H ) \+ ? = / ;
805+ / ( ^ | \s ) ( - - g i t - d i r = ? | - - w o r k - t r e e = ? | - e x e c d i r ) | ( ^ | [ \s ; & | ( ) { } ] ) ( c d | p u s h d ) ( [ \s ; & | ] | $ ) | ( ^ | [ \s ; & | ( ) { } ] ) ( G I T _ D I R | G I T _ W O R K _ T R E E | G I T _ C O M M O N _ D I R | G I T _ I N D E X _ F I L E | G I T _ E X E C _ P A T H | P A T H ) \+ ? = / ;
817806const TEXT_RELOCATION_MARKER_PATTERN =
818- / ( ^ | \s ) ( - C | - - g i t - d i r = ? | - - w o r k - t r e e = ? | - e x e c d i r ) | ( ^ | [ \s ; & | ( ) { } ] ) ( c d | c h d i r | p u s h d ) ( [ \s ; & | ] | $ ) | ( ^ | [ \s ; & | ( ) { } ] ) ( G I T _ D I R | G I T _ W O R K _ T R E E | G I T _ C O M M O N _ D I R | G I T _ I N D E X _ F I L E | G I T _ E X E C _ P A T H | P A T H ) \+ ? = / ;
807+ / ( ^ | \s ) ( - C | - - g i t - d i r = ? | - - w o r k - t r e e = ? | - e x e c d i r ) | ( ^ | [ \s ; & | ( ) { } ] ) ( c d | p u s h d ) ( [ \s ; & | ] | $ ) | ( ^ | [ \s ; & | ( ) { } ] ) ( G I T _ D I R | G I T _ W O R K _ T R E E | G I T _ C O M M O N _ D I R | G I T _ I N D E X _ F I L E | G I T _ E X E C _ P A T H | P A T H ) \+ ? = / ;
819808
820809// Assignments that decide WHICH git binary the run executes. The guard
821810// classifies the program word `git` and then reasons about paths; if the
@@ -1216,18 +1205,11 @@ function findChdirTarget(
12161205 run : GuardToken [ ] ,
12171206 start : number ,
12181207 variant : 'cd' | 'popd' | 'pushd' ,
1219- windows = false ,
12201208) : GuardToken | undefined {
12211209 let index = start ;
12221210 while ( index < run . length ) {
12231211 const token = run [ index ] ! ;
12241212 if ( token . text === '--' ) return run [ index + 1 ] ;
1225- // cmd.exe `cd /D <dir>` also switches the drive; `/D` is an option, not
1226- // the directory.
1227- if ( windows && / ^ \/ [ d D ] $ / . test ( token . text ) ) {
1228- index ++ ;
1229- continue ;
1230- }
12311213 if ( variant === 'cd' && CHDIR_OPTION_PATTERN . test ( token . text ) ) {
12321214 index ++ ;
12331215 continue ;
@@ -1391,55 +1373,6 @@ function analyzeRun(
13911373 for ( const operand of operands ) recordEnvAssignment ( operand , state ) ;
13921374 return { kind : 'export' , state, operands } ;
13931375 }
1394- if (
1395- platform === 'win32' &&
1396- getShellConfiguration ( ) . shell !== 'bash' &&
1397- ( program === 'path' || program === 'doskey' )
1398- ) {
1399- // cmd.exe builtins that change how every later chained command
1400- // resolves: `path` rewrites the executable search path (so which
1401- // `git` runs is no longer provable) and `doskey` installs macros.
1402- state . unresolved = true ;
1403- return { kind : 'export' , state, operands : [ ] } ;
1404- }
1405- if (
1406- platform === 'win32' &&
1407- getShellConfiguration ( ) . shell !== 'bash' &&
1408- ( program === 'set' || program === 'setx' )
1409- ) {
1410- // cmd.exe `set VAR=value` — and `setx VAR value`, which persists past
1411- // the session — mutate the environment every later `&&`-chained command
1412- // executes under, so they carry the same semantics as a POSIX
1413- // `export VAR=value`; route the assignments through that machinery.
1414- // Anything that is not a plain assignment (bare `set`, `/p`/`/a`,
1415- // dynamic operands) is undecidable and fails closed.
1416- const operands = run . slice ( index + 1 ) ;
1417- if ( program === 'setx' ) {
1418- const [ name , value ] = operands ;
1419- if (
1420- operands . length === 2 &&
1421- ! name ! . dynamic &&
1422- ! value ! . dynamic &&
1423- / ^ [ A - Z a - z _ ] [ A - Z a - z 0 - 9 _ ] * $ / . test ( name ! . text )
1424- ) {
1425- recordEnvAssignment (
1426- { text : `${ name ! . text } =${ value ! . text } ` , dynamic : false } ,
1427- state ,
1428- ) ;
1429- return { kind : 'export' , state, operands } ;
1430- }
1431- state . unresolved = true ;
1432- return { kind : 'export' , state, operands : [ ] } ;
1433- }
1434- for ( const operand of operands ) {
1435- if ( operand . dynamic || leadingEnvAssignmentKey ( operand . text ) === null ) {
1436- state . unresolved = true ;
1437- return { kind : 'export' , state, operands : [ ] } ;
1438- }
1439- recordEnvAssignment ( operand , state ) ;
1440- }
1441- return { kind : 'export' , state, operands } ;
1442- }
14431376 if ( program === 'set' ) {
14441377 if ( requestsAllExport ( run , index + 1 ) ) {
14451378 return { kind : 'all-export' , state } ;
@@ -1517,17 +1450,11 @@ function analyzeRun(
15171450 if ( program === 'git' ) {
15181451 return { kind : 'git' , tokens : run . slice ( index ) , state } ;
15191452 }
1520- if (
1521- program === 'cd' ||
1522- program === 'pushd' ||
1523- program === 'popd' ||
1524- ( platform === 'win32' && program === 'chdir' )
1525- ) {
1526- const variant = program === 'chdir' ? 'cd' : program ;
1453+ if ( program === 'cd' || program === 'pushd' || program === 'popd' ) {
15271454 return {
15281455 kind : 'cd' ,
1529- variant,
1530- target : findChdirTarget ( run , index + 1 , variant , platform === 'win32' ) ,
1456+ variant : program ,
1457+ target : findChdirTarget ( run , index + 1 , program ) ,
15311458 // `cd -P` resolves each component through its symlinks before
15321459 // applying `..`, which a lexical resolve cannot reproduce.
15331460 physical : run
@@ -3036,16 +2963,14 @@ async function evaluateCommandWithCwd(
30362963 // symlink race rather than denying every `tar && git commit`.
30372964 if ( trackedCwd !== undefined ) relinkedTargets . push ( trackedCwd ) ;
30382965 }
3039- const relinkPrograms =
3040- platformNow === 'win32'
3041- ? WIN32_PATH_RELINKING_PROGRAMS
3042- : PATH_RELINKING_PROGRAMS ;
3043- if ( run . some ( ( t ) => relinkPrograms . has ( executableBaseName ( t ) ) ) ) {
2966+ if (
2967+ run . some ( ( t ) => PATH_RELINKING_PROGRAMS . has ( executableBaseName ( t ) ) )
2968+ ) {
30442969 // Wrappers and leading assignments (`env ln …`, `X=1 ln …`) keep
30452970 // the relinking program out of run[0], so scan the whole run.
30462971 for ( const operand of run ) {
30472972 if ( operand . text . startsWith ( '-' ) ) continue ;
3048- if ( relinkPrograms . has ( executableBaseName ( operand ) ) ) {
2973+ if ( PATH_RELINKING_PROGRAMS . has ( executableBaseName ( operand ) ) ) {
30492974 continue ;
30502975 }
30512976 if ( operand . dynamic || trackedCwd === undefined ) {
0 commit comments