File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -4261,7 +4261,6 @@ class C(object):
4261
4261
C .__name__ = 'D.E'
4262
4262
self .assertEqual ((C .__module__ , C .__name__ ), (mod , 'D.E' ))
4263
4263
4264
- @unittest .skip ("TODO: RUSTPYTHON, rustpython hang" )
4265
4264
def test_evil_type_name (self ):
4266
4265
# A badly placed Py_DECREF in type_set_name led to arbitrary code
4267
4266
# execution while the type structure was not in a sane state, and a
Original file line number Diff line number Diff line change @@ -680,7 +680,15 @@ impl PyType {
680
680
. heaptype_ext
681
681
. as_ref ( )
682
682
. expect ( "HEAPTYPE should have heaptype_ext" ) ;
683
- * heap_type. qualname . write ( ) = str_value;
683
+
684
+ // Use std::mem::replace to swap the new value in and get the old value out,
685
+ // then drop the old value after releasing the lock
686
+ let _old_qualname = {
687
+ let mut qualname_guard = heap_type. qualname . write ( ) ;
688
+ std:: mem:: replace ( & mut * qualname_guard, str_value)
689
+ } ;
690
+ // old_qualname is dropped here, outside the lock scope
691
+
684
692
Ok ( ( ) )
685
693
}
686
694
@@ -837,7 +845,13 @@ impl PyType {
837
845
return Err ( vm. new_value_error ( "type name must not contain null characters" ) ) ;
838
846
}
839
847
840
- * self . heaptype_ext . as_ref ( ) . unwrap ( ) . name . write ( ) = name;
848
+ // Use std::mem::replace to swap the new value in and get the old value out,
849
+ // then drop the old value after releasing the lock (similar to CPython's Py_SETREF)
850
+ let _old_name = {
851
+ let mut name_guard = self . heaptype_ext . as_ref ( ) . unwrap ( ) . name . write ( ) ;
852
+ std:: mem:: replace ( & mut * name_guard, name)
853
+ } ;
854
+ // old_name is dropped here, outside the lock scope
841
855
842
856
Ok ( ( ) )
843
857
}
You can’t perform that action at this time.
0 commit comments