@@ -307,7 +307,9 @@ php_mbereg_exec(INTERNAL_FUNCTION_PARAMETERS, int icase)
307
307
mbre_free_registers (& regs );
308
308
RETURN_FALSE ;
309
309
}
310
-
310
+ if (regs .beg [0 ] == regs .end [0 ]) {
311
+ php_error_docref (NULL TSRMLS_CC , E_WARNING , "Empty regular expression ");
312
+ }
311
313
match_len = 1 ;
312
314
str = Z_STRVAL_PP (arg_string );
313
315
if (array ) {
@@ -423,6 +425,10 @@ php_mbereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, int option)
423
425
pos = 0 ;
424
426
while (err >= 0 ) {
425
427
err = mbre_search (& re , string , string_len , pos , string_len - pos , & regs );
428
+ if ( regs .beg [0 ] == regs .end [0 ] ) {
429
+ php_error_docref (NULL TSRMLS_CC , E_WARNING , "Empty regular expression ");
430
+ break ;
431
+ }
426
432
if (err <= -2 ) {
427
433
php_error_docref (NULL TSRMLS_CC , E_WARNING , "mbregex search failure in php_mbereg_replace_exec()" );
428
434
break ;
@@ -565,20 +571,19 @@ PHP_FUNCTION(mb_split)
565
571
/* churn through str, generating array entries as we go */
566
572
while ((count != 0 ) &&
567
573
(err = mbre_search (& re , string , string_len , pos , string_len - pos , & regs )) >= 0 ) {
574
+ if ( regs .beg [0 ] == regs .end [0 ] ) {
575
+ php_error_docref (NULL TSRMLS_CC , E_WARNING , "Empty regular expression ");
576
+ break ;
577
+ }
578
+
568
579
n = regs .beg [0 ];
569
- if (n == pos ) {
570
- /* match is at start of string, return empty string */
571
- add_next_index_stringl (return_value , empty_string , 0 , 1 );
580
+ /* add it to the array */
581
+ if (n < string_len && n <= pos ) {
582
+ n -= pos ;
583
+ add_next_index_stringl (return_value , & string [pos ], n , 1 );
572
584
} else {
573
- /* On a real match */
574
- /* add it to the array */
575
- if (n < string_len ) {
576
- n -= pos ;
577
- add_next_index_stringl (return_value , & string [pos ], n , 1 );
578
- } else {
579
- err = -2 ;
580
- break ;
581
- }
585
+ err = -2 ;
586
+ break ;
582
587
}
583
588
/* point at our new starting point */
584
589
n = regs .end [0 ];
@@ -736,14 +741,16 @@ php_mbereg_search_exec(INTERNAL_FUNCTION_PARAMETERS, int mode)
736
741
}
737
742
738
743
err = mbre_search (MBSTRG (search_re ), str , len , pos , len - pos , MBSTRG (search_regs ));
739
-
740
744
if (err <= -2 ) {
741
745
php_error_docref (NULL TSRMLS_CC , E_WARNING , "mbregex search failure in mbregex_search()" );
742
746
RETVAL_FALSE ;
743
747
} else if (err < 0 ) {
744
748
MBSTRG (search_pos ) = len ;
745
749
RETVAL_FALSE ;
746
750
} else {
751
+ if (MBSTRG (search_regs )-> beg [0 ] == MBSTRG (search_regs )-> end [0 ]) {
752
+ php_error_docref (NULL TSRMLS_CC , E_WARNING , "Empty regular expression ");
753
+ }
747
754
switch (mode ) {
748
755
case 1 :
749
756
if (array_init (return_value ) != FAILURE ) {
0 commit comments