File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -833,11 +833,18 @@ PHP_METHOD(SplObjectStorage, serialize)
833833			RETURN_NULL ();
834834		}
835835		ZVAL_OBJ (& obj , element -> obj );
836+ 
837+ 		/* Protect against modification; we need a full copy because the data may be refcounted. */ 
838+ 		zval  inf_copy ;
839+ 		ZVAL_COPY (& inf_copy , & element -> inf );
840+ 
836841		php_var_serialize (& buf , & obj , & var_hash );
837842		smart_str_appendc (& buf , ',' );
838- 		php_var_serialize (& buf , & element -> inf , & var_hash );
843+ 		php_var_serialize (& buf , & inf_copy , & var_hash );
839844		smart_str_appendc (& buf , ';' );
840845		zend_hash_move_forward_ex (& intern -> storage , & pos );
846+ 
847+ 		zval_ptr_dtor (& inf_copy );
841848	}
842849
843850	/* members */ 
Original file line number Diff line number Diff line change 1+ --TEST--
2+ GH-16588 (UAF in Observer->serialize)
3+ --CREDITS--
4+ chibinz
5+ --FILE--
6+ <?php 
7+ 
8+ class  C {
9+     function  __serialize (): array  {
10+         global  $ store ;
11+         $ store ->removeAll ($ store );
12+         return  [];
13+     }
14+ }
15+ 
16+ $ store  = new  SplObjectStorage ;
17+ $ store [new  C ] = new  stdClass ;
18+ var_dump ($ store ->serialize ());
19+ 
20+ ?> 
21+ --EXPECT--
22+ string(47) "x:i:1;O:1:"C":0:{},O:8:"stdClass":0:{};m:a:0:{}"
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments