Skip to content

Commit

Permalink
Item15192: improve fix to $EVAL()
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDaum committed May 22, 2023
1 parent 9c6fb46 commit 7a1d423
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions SpreadSheetPlugin/lib/Foswiki/Plugins/SpreadSheetPlugin/Calc.pm
Expand Up @@ -1730,19 +1730,21 @@ sub _safeEvalPerl {
# keep only numbers and operators
$theText =~ s/[^\!\<\=\>\-\+\*\/\%0-9e\.\(\)]*//g;

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

# remove leading 0s to defuse interpretation of numbers as octals
$theText =~ s/(^|[^\.])\b0+(?=[0-9])/$1/g;

# remove "e"-s unless in expression such as "123e-4"
$theText =~ s/(^|[^0-9])e/$1/g;
$theText =~ /(.*)/;
$theText = $1; # untainted variable
$theText = $1; # untainted variable

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

return "" unless defined($theText);

local $SIG{__DIE__} =
sub { Foswiki::Func::writeDebug( $_[0] ); warn $_[0] };
my $result = eval $theText;
Expand Down

0 comments on commit 7a1d423

Please sign in to comment.