@@ -14,7 +14,7 @@ use Time::HiRes qw/time/;
1414use File::Spec();
1515use File::Temp();
1616
17- use Test2::Harness::Util qw/ fqmod clean_path write_file_atomic write_file mod2file open_file parse_exit process_includes chmod_tmp/ ;
17+ use Test2::Harness::Util qw/ fqmod clean_path write_file_atomic write_file mod2file open_file parse_exit process_includes chmod_tmp untaint / ;
1818use Test2::Harness::IPC;
1919
2020use parent ' Test2::Harness::IPC::Process' ;
@@ -354,7 +354,7 @@ sub job_dir {
354354 my $self = shift ;
355355 return $self -> {+JOB_DIR} if $self -> {+JOB_DIR};
356356
357- my $job_dir = File::Spec-> catdir($self -> run_dir, $self -> {+TASK}-> {job_id } . ' +' . $self -> is_try);
357+ my $job_dir = untaint( File::Spec-> catdir($self -> run_dir, $self -> {+TASK}-> {job_id } . ' +' . $self -> is_try) );
358358 mkdir ($job_dir ) or die " $$ $0 Could not create job directory '$job_dir ': $! " ;
359359 chmod_tmp($job_dir );
360360 $self -> {+JOB_DIR} = $job_dir ;
@@ -415,8 +415,24 @@ sub use_fork {
415415 return $self -> {+USE_FORK} = 0 if defined ($task -> {use_fork }) && !$task -> {use_fork };
416416 return $self -> {+USE_FORK} = 0 if defined ($task -> {use_preload }) && !$task -> {use_preload };
417417
418- # -w switch is ok, otherwise it is a no-go
419- return $self -> {+USE_FORK} = 0 if grep { !m /\s *-w\s */ } $self -> switches;
418+ use Data::Dumper;
419+ warn Dumper [ $self -> switches ];
420+
421+ # Ugh I hate this logic!!!
422+
423+ # This approach won't scale if we allow even more swiches.
424+ my @allowed_switches = ' -w' ;
425+
426+ # Allow taint and taint + warnings if we're a tainted runner.
427+ push @allowed_switches => qw/ -T -wT -Tw/ if ${^TAINT};
428+
429+ my $allowed_switches = join ' |' , map { quotemeta } @allowed_switches ;
430+ my $allowed_switches_re = qr /\s *(?:$allowed_switches )\s */ ;
431+
432+ return $self -> {+USE_FORK} = 0 if grep { $_ !~ $allowed_switches_re } $self -> switches;
433+
434+ # We're running under the taint but the test hasn't requested taint.
435+ return $self -> {+USE_FORK} = 0 if ${^TAINT} && !grep { / \s *-w?Tw?\s */ } $self -> switches;
420436
421437 my $runner = $self -> {+RUNNER};
422438 return $self -> {+USE_FORK} = 0 unless $runner -> use_fork;
0 commit comments