summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Pena <felipe@php.net>2011-11-21 19:15:18 +0000
committerFelipe Pena <felipe@php.net>2011-11-21 19:15:18 +0000
commitf7048d092515fabc3469429eaa249cfce5b1d43a (patch)
tree96ac7cf377afdeeb061cafe2b3478ddb31979c56
parent0d73c76becc4998c632fb108b46ba9dab1274276 (diff)
downloadphp-git-f7048d092515fabc3469429eaa249cfce5b1d43a.tar.gz
- Fixed possible crash in mb_ereg_search_init() using empty pattern
-rw-r--r--NEWS3
-rw-r--r--ext/mbstring/php_mbregex.c9
-rw-r--r--ext/mbstring/tests/empty_pattern.phpt18
3 files changed, 28 insertions, 2 deletions
diff --git a/NEWS b/NEWS
index 203fe9e38e..b49bbb48b7 100644
--- a/NEWS
+++ b/NEWS
@@ -35,6 +35,9 @@ PHP NEWS
. Fixed bug #60160 (imagefill() doesn't work correctly
for small images). (Florian)
+- Mbstring:
+ . Fixed possible crash in mb_ereg_search_init() using empty pattern. (Felipe)
+
- MS SQL:
. Fixed bug #60267 (Compile failure with freetds 0.91). (Felipe)
diff --git a/ext/mbstring/php_mbregex.c b/ext/mbstring/php_mbregex.c
index 9617487c8b..e28bdc4560 100644
--- a/ext/mbstring/php_mbregex.c
+++ b/ext/mbstring/php_mbregex.c
@@ -1245,14 +1245,19 @@ PHP_FUNCTION(mb_ereg_search_init)
{
size_t argc = ZEND_NUM_ARGS();
zval *arg_str;
- char *arg_pattern, *arg_options;
- int arg_pattern_len, arg_options_len;
+ char *arg_pattern = NULL, *arg_options = NULL;
+ int arg_pattern_len = 0, arg_options_len = 0;
OnigSyntaxType *syntax = NULL;
OnigOptionType option;
if (zend_parse_parameters(argc TSRMLS_CC, "z|ss", &arg_str, &arg_pattern, &arg_pattern_len, &arg_options, &arg_options_len) == FAILURE) {
return;
}
+
+ if (arg_pattern_len == 0) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty pattern");
+ RETURN_FALSE;
+ }
option = MBREX(regex_default_options);
syntax = MBREX(regex_default_syntax);
diff --git a/ext/mbstring/tests/empty_pattern.phpt b/ext/mbstring/tests/empty_pattern.phpt
new file mode 100644
index 0000000000..e395604f8e
--- /dev/null
+++ b/ext/mbstring/tests/empty_pattern.phpt
@@ -0,0 +1,18 @@
+--TEST--
+Check for empty pattern
+--SKIPIF--
+<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?>
+--FILE--
+<?php
+
+mb_ereg_search_init("","","");
+mb_split("","");
+mb_ereg_search_regs();
+
+?>
+--EXPECTF--
+Warning: mb_ereg_search_init(): Empty pattern in %s on line %d
+
+Warning: mb_split(): Empty regular expression in %s on line %d
+
+Warning: mb_ereg_search_regs(): No regex given in %s on line %d