[perl #118175] avoid making a pointer outside a string
authorTony Cook <tony@develop-help.com>
Sat, 1 Jun 2013 02:33:05 +0000 (12:33 +1000)
committerTony Cook <tony@develop-help.com>
Mon, 3 Jun 2013 12:05:27 +0000 (22:05 +1000)
Simply adding scan + max causes undefined behaviour per ANSI C if the
result points outside of the object scan points at.

regexec.c

index 87a0d73..d29f6dd 100644 (file)
--- a/regexec.c
+++ b/regexec.c
@@ -6656,7 +6656,7 @@ S_regrepeat(pTHX_ regexp *prog, char **startposp, const regnode *p,
     scan = *startposp;
     if (max == REG_INFTY)
        max = I32_MAX;
-    else if (! utf8_target && scan + max < loceol)
+    else if (! utf8_target && loceol - scan > max)
        loceol = scan + max;
 
     /* Here, for the case of a non-UTF-8 target we have adjusted <loceol> down