Skip to content

Commit

Permalink
maybe_command(): Ensure that command is defined and non-empty
Browse files Browse the repository at this point in the history
As demonstrated in
cpan-testers/CPAN-Reporter#59 (comment),
it is possible to exercise subroutine maybe_command() without a defined
argument.  We should preclude this from happening.
  • Loading branch information
jkeenan committed Oct 9, 2023
1 parent 694b7c7 commit 2691f27
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/ExtUtils/MM_Unix.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2896,6 +2896,8 @@ Returns true, if the argument is likely to be a command.

sub maybe_command {
my($self,$file) = @_;
croak "maybe_command() lacks defined, non-empty argument"
unless (defined $file and length $file);
return $file if -x $file && ! -d $file;
return;
}
Expand Down
20 changes: 18 additions & 2 deletions t/MM_Unix.t
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ BEGIN {
plan skip_all => 'Non-Unix platform';
}
else {
plan tests => 114;
plan tests => 116;
}
}

Expand Down Expand Up @@ -178,7 +178,23 @@ is ($t->libscan('Fatty'), 'Fatty', 'libscan on something not a VC file' );

open(FILE, ">command"); print FILE "foo"; close FILE;
SKIP: {
skip("no separate execute mode on VOS", 2) if $^O eq "vos";
skip("no separate execute mode on VOS", 4) if $^O eq "vos";

{
local $@;
eval { $t->maybe_command( undef ); };
like ($@, qr{\Qmaybe_command() lacks defined, non-empty argument\E},
"maybe_command needs defined argument"
);
}

{
local $@;
eval { $t->maybe_command( '' ); };
like ($@, qr{\Qmaybe_command() lacks defined, non-empty argument\E},
"maybe_command needs non-zero-length argument"
);
}

ok !$t->maybe_command('command') ,"non executable file isn't a command";

Expand Down

0 comments on commit 2691f27

Please sign in to comment.