[Pcre-svn] [1327] code/trunk: Fix pcretest crash with a data…

Top Page
Delete this message
Author: Subversion repository
Date:  
To: pcre-svn
Subject: [Pcre-svn] [1327] code/trunk: Fix pcretest crash with a data line longer than 65536 bytes.
Revision: 1327
          http://vcs.pcre.org/viewvc?view=rev&revision=1327
Author:   ph10
Date:     2013-05-10 17:22:40 +0100 (Fri, 10 May 2013)


Log Message:
-----------
Fix pcretest crash with a data line longer than 65536 bytes.

Modified Paths:
--------------
    code/trunk/ChangeLog
    code/trunk/pcretest.c


Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog    2013-05-10 14:21:41 UTC (rev 1326)
+++ code/trunk/ChangeLog    2013-05-10 16:22:40 UTC (rev 1327)
@@ -156,7 +156,9 @@


41. Applied a user patch to fix a number of spelling mistakes in comments.

+42. Data lines longer than 65536 caused pcretest to crash.

+
Version 8.32 30-November-2012
-----------------------------


Modified: code/trunk/pcretest.c
===================================================================
--- code/trunk/pcretest.c    2013-05-10 14:21:41 UTC (rev 1326)
+++ code/trunk/pcretest.c    2013-05-10 16:22:40 UTC (rev 1327)
@@ -4411,7 +4411,8 @@


 #ifndef NOUTF
     /* Check that the data is well-formed UTF-8 if we're in UTF mode. To create
-       invalid input to pcre_exec, you must use \x?? or \x{} sequences. */
+    invalid input to pcre_exec, you must use \x?? or \x{} sequences. */
+        
     if (use_utf)
       {
       pcre_uint8 *q;
@@ -4429,21 +4430,23 @@


 #ifdef SUPPORT_VALGRIND
     /* Mark the dbuffer as addressable but undefined again. */
+     
     if (dbuffer != NULL)
       {
       VALGRIND_MAKE_MEM_UNDEFINED(dbuffer, dbuffer_size * CHAR_SIZE);
       }
 #endif


-    /* Allocate a buffer to hold the data line. len+1 is an upper bound on
-       the number of pcre_uchar units that will be needed. */
-    if (dbuffer == NULL || (size_t)len >= dbuffer_size)
+    /* Allocate a buffer to hold the data line; len+1 is an upper bound on
+    the number of pcre_uchar units that will be needed. */
+        
+    while (dbuffer == NULL || (size_t)len >= dbuffer_size)
       {
       dbuffer_size *= 2;
       dbuffer = (pcre_uint8 *)realloc(dbuffer, dbuffer_size * CHAR_SIZE);
       if (dbuffer == NULL)
         {
-        fprintf(stderr, "pcretest: malloc(%d) failed\n", (int)dbuffer_size);
+        fprintf(stderr, "pcretest: realloc(%d) failed\n", (int)dbuffer_size);
         exit(1);
         }
       }