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