This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
prevent invalid memory access in S_check_uni (RT #132433)
authorLukas Mai <l.mai@web.de>
Sun, 12 Nov 2017 01:58:32 +0000 (02:58 +0100)
committerLukas Mai <l.mai@web.de>
Sun, 12 Nov 2017 02:15:27 +0000 (03:15 +0100)
t/comp/parser_run.t
toke.c

index eba4b9f..2408fcd 100644 (file)
@@ -10,7 +10,7 @@ BEGIN {
     set_up_inc( qw(. ../lib ) );
 }
 
-plan(4);
+plan(5);
 
 # [perl #130814] can reallocate lineptr while looking ahead for
 # "Missing $ on loop variable" diagnostic.
@@ -49,5 +49,11 @@ SKIP:
     is($out, "", "check for ASAN use after free");
 }
 
+fresh_perl_is('-C-', <<'EXPECTED', {}, "ambiguous unary operator check doesn't crash (#132433)");
+Warning: Use of "-C-" without parentheses is ambiguous at - line 1.
+syntax error at - line 1, at EOF
+Execution of - aborted due to compilation errors.
+EXPECTED
+
 __END__
 # ex: set ts=8 sts=4 sw=4 et:
diff --git a/toke.c b/toke.c
index c8ca63a..3dd4b47 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -1935,7 +1935,7 @@ S_check_uni(pTHX)
     s = PL_last_uni;
     while (isWORDCHAR_lazy_if_safe(s, PL_bufend, UTF) || *s == '-')
        s += UTF ? UTF8SKIP(s) : 1;
-    if (memchr(s, '(', PL_bufptr - s))
+    if (s < PL_bufptr && memchr(s, '(', PL_bufptr - s))
        return;
 
     Perl_ck_warner_d(aTHX_ packWARN(WARN_AMBIGUOUS),