Skip to content

Commit

Permalink
Merge pull request #514 from cpanel/RE-699
Browse files Browse the repository at this point in the history
RE-699: Swap 'return 42' line to Carp::croak()
  • Loading branch information
toddr authored Sep 26, 2024
2 parents 0763f28 + a698ab1 commit 24d0d72
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion elevate-cpanel
Original file line number Diff line number Diff line change
Expand Up @@ -7662,7 +7662,7 @@ EOS
sub _ssystem ( $command, %opts ) {
my @args = @{ $command // [] };

return 42 if $args[0] !~ '^/' || !-x $args[0];
Carp::croak("Program is not an executable absolute path.") if $args[0] !~ '^/' || !-x $args[0];

INFO( "Running: " . join( " ", @args ) );
INFO(); # Buffer so they can more easily read the output.
Expand Down
2 changes: 1 addition & 1 deletion lib/Elevate/Roles/Run.pm
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ sub _ssystem ( $command, %opts ) {
my @args = @{ $command // [] };

# Only allow the program to be an executable absolute path
return 42 if $args[0] !~ '^/' || !-x $args[0];
Carp::croak("Program is not an executable absolute path.") if $args[0] !~ '^/' || !-x $args[0];

INFO( "Running: " . join( " ", @args ) );
INFO(); # Buffer so they can more easily read the output.
Expand Down
26 changes: 22 additions & 4 deletions t/ssystem.t
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,28 @@ my $mock_log_file = Test::MockFile->file('/var/log/elevate-cpanel.log');

my $cpev = cpev->new->_init;

is( cpev->ssystem('nope'), 42, q[ssystem( 'nope' ) is disallowed] );
is( cpev->ssystem('grep'), 42, 'Commands that are not absolute paths are not allowed' );

is( cpev->ssystem('/etc/apache2/conf/httpd.conf'), 42, 'Commands that are not executable are not allowed' );
like(
dies { cpev->ssystem('nope') },
qr/Program is not an executable absolute path/,
'Program is not an executable path.'
);

like(
dies { cpev->ssystem('grep') },
qr/Program is not an executable absolute path/,
'Program is not an executable absolute path.'
);

like(
dies { cpev->ssystem('/etc/apache2/conf/httpd.conf') },
qr/Program is not an executable absolute path/,
'Paths that are not executable are not allowed.'
);

ok(
lives { cpev->ssystem('/bin/true') },
'Program is not an executable absolute path.'
);

is( cpev->ssystem("/bin/true"), 0, q[ssystem( "/bin/true" ) == 0] );
isnt( my $status_false = cpev->ssystem("/bin/false"), 0, q[ssystem( "/bin/false" ) != 0] );
Expand Down

0 comments on commit 24d0d72

Please sign in to comment.