@@ -307,7 +307,9 @@ php_mbereg_exec(INTERNAL_FUNCTION_PARAMETERS, int icase)
307307 mbre_free_registers (& regs );
308308 RETURN_FALSE ;
309309 }
310-
310+ if (regs .beg [0 ] == regs .end [0 ]) {
311+ php_error_docref (NULL TSRMLS_CC , E_WARNING , "Empty regular expression ");
312+ }
311313 match_len = 1 ;
312314 str = Z_STRVAL_PP (arg_string );
313315 if (array ) {
@@ -423,6 +425,10 @@ php_mbereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, int option)
423425 pos = 0 ;
424426 while (err >= 0 ) {
425427 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+ }
426432 if (err <= -2 ) {
427433 php_error_docref (NULL TSRMLS_CC , E_WARNING , "mbregex search failure in php_mbereg_replace_exec()" );
428434 break ;
@@ -565,20 +571,19 @@ PHP_FUNCTION(mb_split)
565571 /* churn through str, generating array entries as we go */
566572 while ((count != 0 ) &&
567573 (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+
568579 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 );
572584 } 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 ;
582587 }
583588 /* point at our new starting point */
584589 n = regs .end [0 ];
@@ -736,14 +741,16 @@ php_mbereg_search_exec(INTERNAL_FUNCTION_PARAMETERS, int mode)
736741 }
737742
738743 err = mbre_search (MBSTRG (search_re ), str , len , pos , len - pos , MBSTRG (search_regs ));
739-
740744 if (err <= -2 ) {
741745 php_error_docref (NULL TSRMLS_CC , E_WARNING , "mbregex search failure in mbregex_search()" );
742746 RETVAL_FALSE ;
743747 } else if (err < 0 ) {
744748 MBSTRG (search_pos ) = len ;
745749 RETVAL_FALSE ;
746750 } 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+ }
747754 switch (mode ) {
748755 case 1 :
749756 if (array_init (return_value ) != FAILURE ) {
0 commit comments