diff --git a/ChangeLog b/ChangeLog index e373ec9..32dbb3d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -299,6 +299,8 @@ regcomp() error instead of waiting for regexec() to pick it up. 88. In pcre2_substitute(), ensure that CRLF is not split when it is a valid newline sequence. +89. Paranoid check in regcomp() for bad error code from pcre2_compile(). + Version 10.20 30-June-2015 -------------------------- diff --git a/src/pcre2posix.c b/src/pcre2posix.c index 61a0f58..dc36e45 100644 --- a/src/pcre2posix.c +++ b/src/pcre2posix.c @@ -217,8 +217,13 @@ preg->re_erroffset = erroffset; if (preg->re_pcre2_code == NULL) { unsigned int i; - if (errorcode < 0) return REG_BADPAT; /* UTF error */ + + /* A negative value is a UTF error; otherwise all error codes are greater + than COMPILE_ERROR_BASE, but check, just in case. */ + + if (errorcode < COMPILE_ERROR_BASE) return REG_BADPAT; errorcode -= COMPILE_ERROR_BASE; + if (errorcode < (int)(sizeof(eint1)/sizeof(const int))) return eint1[errorcode]; for (i = 0; i < sizeof(eint2)/(2*sizeof(const int)); i += 2)