@@ -2114,7 +2114,7 @@ magiccheck(struct magic_set *ms, struct magic *m)
21142114haystack  =  estrndup (ms -> search .s , ms -> search .s_len );
21152115
21162116/* match v = 0, no match v = 1 */ 
2117- php_pcre_match_impl (pce , haystack , ms -> search .s_len , retval , subpats , 1 , 1 , PREG_OFFSET_CAPTURE , 0  TSRMLS_CC );
2117+ php_pcre_match_impl (pce , haystack , ms -> search .s_len , retval , subpats , 0 , 1 , PREG_OFFSET_CAPTURE , 0  TSRMLS_CC );
21182118/* Free haystack */ 
21192119efree (haystack );
21202120
@@ -2125,98 +2125,37 @@ magiccheck(struct magic_set *ms, struct magic *m)
21252125FREE_ZVAL (pattern );
21262126return  -1 ;
21272127} else  if  ((Z_LVAL_P (retval ) >  0 ) &&  (Z_TYPE_P (subpats ) ==  IS_ARRAY )) {
2128- 
21292128/* Need to fetch global match which equals pmatch[0] */ 
2129+ zval  * * ppzval ;
21302130HashTable  * ht  =  Z_ARRVAL_P (subpats );
2131- HashPosition  outer_pos ;
2132- zval  * pattern_match  =  NULL , * pattern_offset  =  NULL ;
2133- 
2134- zend_hash_internal_pointer_reset_ex (ht , & outer_pos ); 
2135- 
2136- if  (zend_hash_has_more_elements_ex (ht , & outer_pos ) ==  SUCCESS  && 
2137- zend_hash_move_forward_ex (ht , & outer_pos )) {
2138- 
2139- zval  * * ppzval ;
2140- 
2141- /* The first element (should be) is the global match  
2142-  Need to move to the inner array to get the global match */ 
2143- 
2144- if  (zend_hash_get_current_data_ex (ht , (void * * )& ppzval , & outer_pos ) !=  FAILURE ) { 
2145- 
2146- HashTable  * inner_ht ;
2147- HashPosition  inner_pos ;
2148- zval  * * match , * * offset ;
2149- zval  tmpcopy  =  * * ppzval , matchcopy , offsetcopy ;
2150- 
2151- zval_copy_ctor (& tmpcopy ); 
2152- INIT_PZVAL (& tmpcopy );
2153- 
2154- inner_ht  =  Z_ARRVAL (tmpcopy );
2155- 
2156- /* If everything goes according to the master plan 
2157-  tmpcopy now contains two elements: 
2158-  0 = the match 
2159-  1 = starting position of the match */ 
2160- zend_hash_internal_pointer_reset_ex (inner_ht , & inner_pos ); 
2161- 
2162- if  (zend_hash_has_more_elements_ex (inner_ht , & inner_pos ) ==  SUCCESS  && 
2163- zend_hash_move_forward_ex (inner_ht , & inner_pos )) {
2164- 
2165- if  (zend_hash_get_current_data_ex (inner_ht , (void * * )& match , & inner_pos ) !=  FAILURE ) { 
2166- 
2167- matchcopy  =  * * match ;
2168- zval_copy_ctor (& matchcopy );
2169- INIT_PZVAL (& matchcopy );
2170- convert_to_string (& matchcopy ); 
2171- 
2172- MAKE_STD_ZVAL (pattern_match );
2173- Z_STRVAL_P (pattern_match ) =  (char  * )Z_STRVAL (matchcopy );
2174- Z_STRLEN_P (pattern_match ) =  Z_STRLEN (matchcopy );
2175- Z_TYPE_P (pattern_match ) =  IS_STRING ; 
2176- 
2177- zval_dtor (& matchcopy );
2178- }
2131+ /* The first element (should be) is the global match  
2132+  Need to move to the inner array to get the global match */ 
2133+ if  (zend_hash_index_find (ht , 0 , (void  * * )& ppzval ) ==  SUCCESS ) {
2134+ zval  * * match , * * offset ;
2135+ /* If everything goes according to the master plan 
2136+  tmpcopy now contains two elements: 
2137+  0 = the match 
2138+  1 = starting position of the match */ 
2139+ if  (zend_hash_index_find (Z_ARRVAL_PP (ppzval ), 0 , (void  * * )& match ) ==  SUCCESS  
2140+ &&  zend_hash_index_find (Z_ARRVAL_PP (ppzval ), 1 , (void  * * )& offset ) ==  SUCCESS ) {
2141+ if  (Z_TYPE_PP (match ) !=  IS_STRING  ||  Z_TYPE_PP (offset ) !=  IS_LONG ) {
2142+ goto error_out ;
21792143}
2180- 
2181- if  (zend_hash_has_more_elements_ex (inner_ht , & inner_pos ) ==  SUCCESS  && 
2182- zend_hash_move_forward_ex (inner_ht , & inner_pos )) {
2183- 
2184- if  (zend_hash_get_current_data_ex (inner_ht , (void * * )& offset , & inner_pos ) !=  FAILURE ) { 
2185- 
2186- offsetcopy  =  * * offset ;
2187- zval_copy_ctor (& offsetcopy );
2188- INIT_PZVAL (& offsetcopy );
2189- convert_to_long (& offsetcopy ); 
2190- 
2191- MAKE_STD_ZVAL (pattern_offset );
2192- Z_LVAL_P (pattern_offset ) =  Z_LVAL (offsetcopy );
2193- Z_TYPE_P (pattern_offset ) =  IS_LONG ;
2194- 
2195- zval_dtor (& offsetcopy );
2196- }
2197- }
2198- zval_dtor (& tmpcopy ); 
2199- }
2200- 
2201- if  ((pattern_match  !=  NULL ) &&  (pattern_offset  !=  NULL )) {
2202- ms -> search .s  +=  (int )Z_LVAL_P (pattern_offset ); /* this is where the match starts */ 
2203- ms -> search .offset  +=  (size_t )Z_LVAL_P (pattern_offset ); /* this is where the match starts as size_t */ 
2204- ms -> search .rm_len  =  Z_STRLEN_P (pattern_match ) /* This is the length of the matched pattern */ ;
2144+ ms -> search .s  +=  (int )Z_LVAL_PP (offset ); /* this is where the match starts */ 
2145+ ms -> search .offset  +=  (size_t )Z_LVAL_PP (offset ); /* this is where the match starts as size_t */ 
2146+ ms -> search .rm_len  =  Z_STRLEN_PP (match ) /* This is the length of the matched pattern */ ;
22052147v  =  0 ;
2206- 
2207- efree (pattern_match );
2208- efree (pattern_offset );
2209- 
22102148} else  {
2211- zval_ptr_dtor (& subpats );
2212- FREE_ZVAL (retval );
2213- zval_dtor (pattern );
2214- FREE_ZVAL (pattern );
2215- return  -1 ;
2149+ goto error_out ;
22162150}
2151+ } else  {
2152+ error_out :
2153+ zval_ptr_dtor (& subpats );
2154+ FREE_ZVAL (retval );
2155+ zval_dtor (pattern );
2156+ FREE_ZVAL (pattern );
2157+ return  -1 ;
22172158}
2218- 
2219- 
22202159} else  {
22212160v  =  1 ;
22222161}
0 commit comments