From e8d55f27af460b2aea0e4f6867acad7ae6e154cc Mon Sep 17 00:00:00 2001 From: Tony Cook Date: Thu, 19 Oct 2017 10:46:04 +1100 Subject: [PATCH] (perl #132245) don't try to process a char range with no preceding char A range like \N{}-0 eventually results in compilation failing, but before that, get_and_check_backslash_N_name() attempts to treat the memory before the empty output of \N{} as a character. --- t/lib/croak/toke | 6 ++++++ toke.c | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/t/lib/croak/toke b/t/lib/croak/toke index 87d958020a0c..1a7468faf522 100644 --- a/t/lib/croak/toke +++ b/t/lib/croak/toke @@ -413,3 +413,9 @@ EXPECT Illegal operator following parameter in a subroutine signature at - line 3, near "($a += 1" syntax error at - line 3, near "($a += 1" Execution of - aborted due to compilation errors. +######## +# NAME tr/// range with empty \N{} at the start +tr//\N{}-0/; +EXPECT +Unknown charname '' at - line 1, within string +Execution of - aborted due to compilation errors. diff --git a/toke.c b/toke.c index e7208babec38..68ec96bdf432 100644 --- a/toke.c +++ b/toke.c @@ -2969,9 +2969,9 @@ S_scan_const(pTHX_ char *start) /* Here, we don't think we're in a range. If the new character * is not a hyphen; or if it is a hyphen, but it's too close to - * either edge to indicate a range, then it's a regular - * character. */ - if (*s != '-' || s >= send - 1 || s == start) { + * either edge to indicate a range, or if we haven't output any + * characters yet then it's a regular character. */ + if (*s != '-' || s >= send - 1 || s == start || d == SvPVX(sv)) { /* A regular character. Process like any other, but first * clear any flags */