Skip to content

Commit

Permalink
Item15192: improved fix to $EVAL()
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDaum committed May 22, 2023
1 parent e3afa2c commit 7300b56
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Expand Up @@ -1739,9 +1739,9 @@ sub _safeEvalPerl {
$theText = $1; # untainted variable

# disable glob for security reasons
$theText =~ s/^([\(\s]*)\<+/$1/g;
$theText =~ s/\>+([\s\)]*)$/$1/g;
$theText =~ s/\<[\.\*\/\?\s]*\>/ /g;
while ( $theText =~ s/\<[\.\*\/\?\se]*\>/ /g ) {
1;
}

return "" unless defined($theText);

Expand Down
Expand Up @@ -437,11 +437,13 @@ sub test_EVAL {
sub test_EVAL_GLOB {
my ($this) = @_;

$this->assert( $this->CALC('$EVAL(<*>)') =~ /^ERROR:/ );
$this->assert( $this->CALC('$EVAL((<*>))') =~ /^ERROR:/ );
$this->assert( $this->CALC('$EVAL(< * >)') =~ /^ERROR:/ );
$this->assert( $this->CALC('$EVAL(<../../../ee*/* >)') =~ /^ERROR:/ );
$this->assert( $this->CALC('$EVAL(<>)') == 0 );
$this->assert( $this->CALC('$EVAL(<<>>)') == 0 );
$this->assert( $this->CALC('$EVAL(<<<>>>)') == 0 );
$this->assert( $this->CALC('$EVAL(<*>)') == 0 );
$this->assert( $this->CALC('$EVAL((<*>))') == 0 );
$this->assert( $this->CALC('$EVAL(< * >)') == 0 );
$this->assert( $this->CALC('$EVAL(<../../../ee*/* >)') == 0 );
$this->assert( $this->CALC('$EVAL(2+<>+2)') == 4 );
$this->assert( $this->CALC('$EVAL(2+< >+2)') == 4 );
$this->assert( $this->CALC('$EVAL(%+.<*>.2)') =~ /^ERROR:/ );
Expand All @@ -450,6 +452,8 @@ sub test_EVAL_GLOB {
$this->assert( $this->CALC('$EVAL(%-.<*>.2)') =~ /^ERROR:/ );
$this->assert( $this->CALC('$EVAL(%+.<../*>.2)') =~ /^ERROR:/ );
$this->assert( $this->CALC('$EVAL(3-<../*>-3)') == 6 );
$this->assert( $this->CALC('$EVAL(%-.<ee*/..>.%-)') =~ /^ERROR:/ );
$this->assert( $this->CALC('$EVAL(%-.<<>../*>.%-)') =~ /^ERROR:/ );
}

sub test_EVEN {
Expand Down

0 comments on commit 7300b56

Please sign in to comment.