diff --git a/ChangeLog b/ChangeLog index 8855f40..0e2deb8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -134,6 +134,8 @@ RunTest (see 4 above). 34. Fix comment describing the returns from find_fixedlength(). +35. Fix potential negative index in pcre2test. + Version 10.21 12-January-2016 ----------------------------- diff --git a/src/pcre2test.c b/src/pcre2test.c index 72415e1..622dad3 100644 --- a/src/pcre2test.c +++ b/src/pcre2test.c @@ -3016,9 +3016,13 @@ for (;;) } dlen = strlen((char *)here); - if (here[dlen - 1] == '\n') return start; /* End of line reached */ here += dlen; + /* Check for end of line reached. Take care not to read data from before + start (dlen will be zero for a file starting with a binary zero). */ + + if (here > start && here[-1] == '\n') return start; + /* If we have not read a newline when reading a file, we have either filled the buffer or reached the end of the file. We can detect the former by checking that the string fills the buffer, and the latter by feof(). If