Detect overlong patterns earlier.

This commit is contained in:
Philip.Hazel 2017-01-03 11:35:26 +00:00
parent 84601d910b
commit 15c30bf55a
2 changed files with 11 additions and 2 deletions

View File

@ -306,6 +306,9 @@ In addition, colour settings containing anything other than digits and
semicolon are ignored, and the colour controls are no longer output for empty semicolon are ignored, and the colour controls are no longer output for empty
strings. strings.
47. Detecting patterns that are too large inside the length-measuring loop
saves processing ridiculously long patterns to their end.
Version 10.22 29-July-2016 Version 10.22 29-July-2016
-------------------------- --------------------------

View File

@ -4693,6 +4693,11 @@ for (;; pptr++)
return 0; return 0;
} }
*lengthptr += (PCRE2_SIZE)(code - orig_code); *lengthptr += (PCRE2_SIZE)(code - orig_code);
if (*lengthptr > MAX_PATTERN_SIZE)
{
*errorcodeptr = ERR20; /* Pattern is too large */
return 0;
}
code = orig_code; code = orig_code;
} }
@ -7334,7 +7339,6 @@ for (;;)
} }
*lengthptr += length; *lengthptr += length;
} }
// if (lengthptr == NULL) fprintf(stderr, "~~group returns %d\n", okreturn);
return okreturn; return okreturn;
} }
@ -9075,6 +9079,8 @@ code = cworkspace;
if (errorcode != 0) goto HAD_CB_ERROR; /* Offset is in cb.erroroffset */ if (errorcode != 0) goto HAD_CB_ERROR; /* Offset is in cb.erroroffset */
/* This should be caught in compile_regex(), but just in case... */
if (length > MAX_PATTERN_SIZE) if (length > MAX_PATTERN_SIZE)
{ {
errorcode = ERR20; errorcode = ERR20;