c1b0704
From 8d020224667f838efb4240da0990666f196b2cfc Mon Sep 17 00:00:00 2001
c1b0704
From: ph10 <ph10@6239d852-aaf2-0410-a92c-79f79f948069>
c1b0704
Date: Thu, 23 Feb 2017 17:05:43 +0000
c1b0704
Subject: [PATCH] Check malloc returns in pcre2test.
c1b0704
MIME-Version: 1.0
c1b0704
Content-Type: text/plain; charset=UTF-8
c1b0704
Content-Transfer-Encoding: 8bit
c1b0704
c1b0704
git-svn-id: svn://vcs.exim.org/pcre2/code/trunk@669 6239d852-aaf2-0410-a92c-79f79f948069
c1b0704
c1b0704
Petr Písař: Ported to 10.21.
c1b0704
c1b0704
Signed-off-by: Petr Písař <ppisar@redhat.com>
c1b0704
---
c1b0704
 src/pcre2test.c      | 22 +++++++++++++++++++---
c1b0704
 testdata/testinput2  |  3 +++
c1b0704
 testdata/testoutput2 |  4 ++++
c1b0704
 3 files changed, 26 insertions(+), 3 deletions(-)
c1b0704
c1b0704
diff --git a/src/pcre2test.c b/src/pcre2test.c
c1b0704
index 10c6a49..4d4cf46 100644
c1b0704
--- a/src/pcre2test.c
c1b0704
+++ b/src/pcre2test.c
c1b0704
@@ -1315,8 +1315,7 @@ are supported. */
c1b0704
   (test_mode == PCRE8_MODE && G(x,8)->f r (y)) || \
c1b0704
   (test_mode == PCRE16_MODE && G(x,16)->f r (y)) || \
c1b0704
   (test_mode == PCRE32_MODE && G(x,32)->f r (y)))
c1b0704
-
c1b0704
-
c1b0704
+  
c1b0704
 
c1b0704
 /* ----- Two out of three modes are supported ----- */
c1b0704
 
c1b0704
@@ -1707,7 +1706,7 @@ the three different cases. */
c1b0704
 #define TESTFLD(x,f,r,y) ( \
c1b0704
   (test_mode == G(G(PCRE,BITONE),_MODE) && G(x,BITONE)->f r (y)) || \
c1b0704
   (test_mode == G(G(PCRE,BITTWO),_MODE) && G(x,BITTWO)->f r (y)))
c1b0704
-
c1b0704
+  
c1b0704
 
c1b0704
 #endif  /* Two out of three modes */
c1b0704
 
c1b0704
@@ -5791,7 +5790,16 @@ if ((pat_patctl.control & CTL_POSIX) != 0)
c1b0704
   if (msg[0] == 0) fprintf(outfile, "\n");
c1b0704
 
c1b0704
   if (dat_datctl.oveccount > 0)
c1b0704
+    { 
c1b0704
     pmatch = (regmatch_t *)malloc(sizeof(regmatch_t) * dat_datctl.oveccount);
c1b0704
+    if (pmatch == NULL)
c1b0704
+      {
c1b0704
+      fprintf(outfile, "** Failed to get memory for recording matching "
c1b0704
+        "information (size set = %du)\n", dat_datctl.oveccount);
c1b0704
+      return PR_OK;     
c1b0704
+      }     
c1b0704
+    }   
c1b0704
+ 
c1b0704
   if ((dat_datctl.options & PCRE2_NOTBOL) != 0) eflags |= REG_NOTBOL;
c1b0704
   if ((dat_datctl.options & PCRE2_NOTEOL) != 0) eflags |= REG_NOTEOL;
c1b0704
   if ((dat_datctl.options & PCRE2_NOTEMPTY) != 0) eflags |= REG_NOTEMPTY;
c1b0704
@@ -5928,6 +5936,14 @@ else
c1b0704
   PCRE2_MATCH_DATA_CREATE(match_data, max_oveccount, NULL);
c1b0704
   }
c1b0704
 
c1b0704
+if (CASTVAR(void *, match_data) == NULL)
c1b0704
+  {
c1b0704
+  fprintf(outfile, "** Failed to get memory for recording matching "
c1b0704
+    "information (size requested: %d)\n", dat_datctl.oveccount);
c1b0704
+  max_oveccount = 0;   
c1b0704
+  return PR_OK;     
c1b0704
+  }     
c1b0704
+
c1b0704
 /* Replacement processing is ignored for DFA matching. */
c1b0704
 
c1b0704
 if (dat_datctl.replacement[0] != 0 && (dat_datctl.control & CTL_DFA) != 0)
c1b0704
diff --git a/testdata/testinput2 b/testdata/testinput2
c1b0704
index ffa5e14..7e26f05 100644
c1b0704
--- a/testdata/testinput2
c1b0704
+++ b/testdata/testinput2
c1b0704
@@ -4822,4 +4822,7 @@ a)"xI
c1b0704
 //replace=0
c1b0704
 \=offset=7
c1b0704
 
c1b0704
+//
c1b0704
+    \=ovector=7777777777
c1b0704
+
c1b0704
 # End of testinput2 
c1b0704
diff --git a/testdata/testoutput2 b/testdata/testoutput2
c1b0704
index 65eda68..b35b207 100644
c1b0704
--- a/testdata/testoutput2
c1b0704
+++ b/testdata/testoutput2
c1b0704
@@ -15220,4 +15220,8 @@ Failed: error -57 at offset 2 in replacement: bad escape sequence in replacement
c1b0704
 \=offset=7
c1b0704
 Failed: error -33: bad offset value
c1b0704
 
c1b0704
+//
c1b0704
+    \=ovector=7777777777
c1b0704
+** Invalid value in 'ovector=7777777777'
c1b0704
+
c1b0704
 # End of testinput2 
c1b0704
-- 
c1b0704
2.7.4
c1b0704