[Pcre-svn] [498] code/trunk: Fix pcre2test bug when snprintf…

Top Page
Delete this message
Author: Subversion repository
Date:  
To: pcre-svn
Subject: [Pcre-svn] [498] code/trunk: Fix pcre2test bug when snprintf() in regerror() does not insert a binary zero.
Revision: 498
          http://www.exim.org/viewvc/pcre2?view=rev&revision=498
Author:   ph10
Date:     2016-02-27 12:49:00 +0000 (Sat, 27 Feb 2016)
Log Message:
-----------
Fix pcre2test bug when snprintf() in regerror() does not insert a binary zero.


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


Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog    2016-02-27 12:10:40 UTC (rev 497)
+++ code/trunk/ChangeLog    2016-02-27 12:49:00 UTC (rev 498)
@@ -72,7 +72,14 @@
 15. Implemented pcre2_code_copy(), and added pushcopy and #popcopy to pcre2test 
 for testing it.


+16. Change 66 for 10.21 introduced the use of snprintf() in PCRE2's version of
+regerror(). When the error buffer is too small, my version of snprintf() puts a
+binary zero in the final byte. Bug #1801 seems to show that other versions do
+not do this, leading to bad output from pcre2test when it was checking for
+buffer overflow. It no longer assumes a binary zero at the end of a too-small
+regerror() buffer.

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

@@ -443,7 +450,7 @@
PCRE2_EXTENDED, and there was no subsequent (?x) to turn it on again,
pcre2_compile() assumed that (?-x) applied to the whole pattern and
consequently mis-compiled it. This bug was found by the LLVM fuzzer. The fix
-for this bug means that a setting of any of the (?imsxU) options at the start
+for this bug means that a setting of any of the (?imsxJU) options at the start
of a pattern is no longer transferred to the options that are returned by
PCRE2_INFO_ALLOPTIONS. In fact, this was an anachronism that should have
changed when the effects of those options were all moved to compile time.

Modified: code/trunk/src/pcre2test.c
===================================================================
--- code/trunk/src/pcre2test.c    2016-02-27 12:10:40 UTC (rev 497)
+++ code/trunk/src/pcre2test.c    2016-02-27 12:49:00 UTC (rev 498)
@@ -4769,6 +4769,7 @@
   if (rc != 0)
     {
     size_t bsize, usize;
+    int psize; 


     preg.re_pcre2_code = NULL;     /* In case something was left in there */
     preg.re_match_data = NULL;
@@ -4779,7 +4780,8 @@
       memcpy(pbuffer8 + bsize, "DEADBEEF", 8);
     usize = regerror(rc, &preg, (char *)pbuffer8, bsize);


-    fprintf(outfile, "Failed: POSIX code %d: %s\n", rc, pbuffer8);
+    psize = (int)bsize;
+    fprintf(outfile, "Failed: POSIX code %d: %.*s\n", rc, psize, pbuffer8);
     if (usize > bsize)
       {
       fprintf(outfile, "** regerror() message truncated\n");