File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ """Test for gh-143545: UAF in lsprof via re-entrant external timer."""
2+ import unittest
3+ import cProfile
4+
5+
6+ class ReentrantTimerTest (unittest .TestCase ):
7+ """Test that profiler handles re-entrant timer correctly."""
8+
9+ def test_reentrant_timer_index (self ):
10+ """Clearing profiler during timer.__index__ should not crash."""
11+
12+ class Timer :
13+ def __init__ (self , profiler ):
14+ self .profiler = profiler
15+
16+ def __call__ (self ):
17+ return self
18+
19+ def __index__ (self ):
20+ self .profiler .clear ()
21+ return 0
22+
23+ prof = cProfile .Profile ()
24+ prof .timer = Timer (prof )
25+
26+ def victim ():
27+ pass
28+
29+ # Should not crash with use-after-free
30+ try :
31+ prof ._pystart_callback (victim .__code__ , 0 )
32+ except (RuntimeError , ValueError ):
33+ pass # Expected if we block the operation
34+
35+
36+ if __name__ == '__main__' :
37+ unittest .main ()
You can’t perform that action at this time.
0 commit comments