[Pcre-svn] [525] code/trunk: Fix possible negative index pos…

Top Page
Delete this message
Author: Subversion repository
Date:  
To: pcre-svn
Subject: [Pcre-svn] [525] code/trunk: Fix possible negative index possibility in pcre2test.
Revision: 525
          http://www.exim.org/viewvc/pcre2?view=rev&revision=525
Author:   ph10
Date:     2016-06-14 17:14:52 +0100 (Tue, 14 Jun 2016)
Log Message:
-----------
Fix possible negative index possibility in pcre2test.


Modified Paths:
--------------
    code/trunk/ChangeLog
    code/trunk/src/pcre2test.c


Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog    2016-06-14 15:12:07 UTC (rev 524)
+++ code/trunk/ChangeLog    2016-06-14 16:14:52 UTC (rev 525)
@@ -134,7 +134,9 @@


34. Fix comment describing the returns from find_fixedlength().

+35. Fix potential negative index in pcre2test.

+
Version 10.21 12-January-2016
-----------------------------


Modified: code/trunk/src/pcre2test.c
===================================================================
--- code/trunk/src/pcre2test.c    2016-06-14 15:12:07 UTC (rev 524)
+++ code/trunk/src/pcre2test.c    2016-06-14 16:14:52 UTC (rev 525)
@@ -3016,9 +3016,13 @@
       }


     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