Skip to content

Commit

Permalink
Move security RT#131079 fix from Grammar to Actions
Browse files Browse the repository at this point in the history
  This lets us catch compound name cases
  Use appropriate syntax errors before flagging restricted status
  Give prohibition on longname aliases a typed exception
  • Loading branch information
skids committed Sep 28, 2017
1 parent 7363f89 commit 2448195
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
18 changes: 17 additions & 1 deletion src/Perl6/Actions.nqp
Expand Up @@ -9922,6 +9922,22 @@ class Perl6::RegexActions is QRegex::P6Regex::Actions does STDActions {
my $qast;
# We got something like <::($foo)>
if $lng.contains_indirect_lookup() {
if $<assertion> {
if +$lng.components() > 1 {
$/.typed_panic('X::Syntax::Regex::Alias::LongName');
}
else {
# If ever implemented, take care with RESTRICTED
$/.typed_panic('X::Syntax::Reserved', :reserved('dynamic alias name in regex'));
}
}
if +$lng.components() > 1 {
# If ever implemented, take care with RESTRICTED
$/.typed_panic('X::NYI', :feature('long dynamic name in regex assertion'));
}
if $*RESTRICTED {
$/.typed_panic('X::SecurityPolicy::Eval', :payload($*RESTRICTED));
}
$qast := QAST::Regex.new( :rxtype<subrule>, :subtype<method>, :node($/),
QAST::NodeList.new(QAST::SVal.new( :value('INDMETHOD') ), $lng.name_past()) );
}
Expand All @@ -9931,7 +9947,7 @@ class Perl6::RegexActions is QRegex::P6Regex::Actions does STDActions {
my $c := $/;
if $<assertion> {
if +@parts {
$c.panic("Can only alias to a short name (without '::')");
$c.typed_panic('X::Syntax::Regex::Alias::LongName');
}
$qast := $<assertion>.ast;
if $qast.rxtype eq 'subrule' {
Expand Down
1 change: 0 additions & 1 deletion src/Perl6/Grammar.nqp
Expand Up @@ -5421,7 +5421,6 @@ grammar Perl6::RegexGrammar is QRegex::P6Regex::Grammar does STD does MatchPacka
}
token assertion:sym<name> {
<!before '::' <RESTRICTED>>
<longname=.LANG('MAIN','longname')>
[
| <?[>]>
Expand Down
4 changes: 4 additions & 0 deletions src/core/Exception.pm
Expand Up @@ -1708,6 +1708,10 @@ my class X::Syntax::Regex::SolitaryBacktrackControl does X::Syntax {
method message { "Backtrack control ':' does not seem to have a preceding atom to control" }
}

my class X::Syntax::Regex::Alias::LongName does X::Syntax {
method message() { "Can only alias to a short name (without '::')"; }
}

my class X::Syntax::Term::MissingInitializer does X::Syntax {
method message { 'Term definition requires an initializer' }
}
Expand Down

0 comments on commit 2448195

Please sign in to comment.