dcb3b7
From a26907949ed561dccd661fc8600889eddc6664ea Mon Sep 17 00:00:00 2001
dcb3b7
From: Hugo van der Sanden <hv@crypt.org>
dcb3b7
Date: Wed, 5 Oct 2016 14:53:27 +0100
dcb3b7
Subject: [PATCH] [perl #129342] ensure range-start is set after error in tr///
dcb3b7
MIME-Version: 1.0
dcb3b7
Content-Type: text/plain; charset=UTF-8
dcb3b7
Content-Transfer-Encoding: 8bit
dcb3b7
dcb3b7
Ported to 5.24.1:
dcb3b7
dcb3b7
t 59143e29a717d67a61b869a6c5bb49574f1ef43f
dcb3b7
Author: Tony Cook <tony@develop-help.com>
dcb3b7
Date:   Tue Jan 17 11:52:53 2017 +1100
dcb3b7
dcb3b7
    (perl #129342) test for buffer overflow
dcb3b7
dcb3b7
commit 3dd4eaeb8ac39e08179145b86aedda36584a3509
dcb3b7
Author: Hugo van der Sanden <hv@crypt.org>
dcb3b7
Date:   Wed Oct 5 14:53:27 2016 +0100
dcb3b7
dcb3b7
    [perl #129342] ensure range-start is set after error in tr///
dcb3b7
dcb3b7
    A parse error due to invalid octal or hex escape in the range of a
dcb3b7
    transliteration must still ensure some kind of start and end values
dcb3b7
    are captured, since we don't stop on the first such error. Failure
dcb3b7
    to do so can cause invalid reads after "Here we have parsed a range".
dcb3b7
dcb3b7
Signed-off-by: Petr Písař <ppisar@redhat.com>
dcb3b7
---
dcb3b7
 t/lib/croak/toke | 7 +++++++
dcb3b7
 toke.c           | 4 ++--
dcb3b7
 2 files changed, 9 insertions(+), 2 deletions(-)
dcb3b7
dcb3b7
diff --git a/t/lib/croak/toke b/t/lib/croak/toke
dcb3b7
index 18dfa24..578a6da 100644
dcb3b7
--- a/t/lib/croak/toke
dcb3b7
+++ b/t/lib/croak/toke
dcb3b7
@@ -302,3 +302,10 @@ Execution of - aborted due to compilation errors.
dcb3b7
 BEGIN <>
dcb3b7
 EXPECT
dcb3b7
 Illegal declaration of subroutine BEGIN at - line 1.
dcb3b7
+########
dcb3b7
+# NAME tr/// handling of mis-formatted \o characters
dcb3b7
+# may only fail with ASAN
dcb3b7
+tr/\o-0//;
dcb3b7
+EXPECT
dcb3b7
+Missing braces on \o{} at - line 2, within string
dcb3b7
+Execution of - aborted due to compilation errors.
dcb3b7
diff --git a/toke.c b/toke.c
dcb3b7
index 288f372..576ce72 100644
dcb3b7
--- a/toke.c
dcb3b7
+++ b/toke.c
dcb3b7
@@ -3338,7 +3338,7 @@ S_scan_const(pTHX_ char *start)
dcb3b7
                                                UTF);
dcb3b7
 		    if (! valid) {
dcb3b7
 			yyerror(error);
dcb3b7
-			continue;
dcb3b7
+			uv = 0; /* drop through to ensure range ends are set */
dcb3b7
 		    }
dcb3b7
 		    goto NUM_ESCAPE_INSERT;
dcb3b7
 		}
dcb3b7
@@ -3356,7 +3356,7 @@ S_scan_const(pTHX_ char *start)
dcb3b7
                                                UTF);
dcb3b7
 		    if (! valid) {
dcb3b7
 			yyerror(error);
dcb3b7
-			continue;
dcb3b7
+			uv = 0; /* drop through to ensure range ends are set */
dcb3b7
 		    }
dcb3b7
 		}
dcb3b7
 
dcb3b7
-- 
dcb3b7
2.7.4
dcb3b7