File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -76,29 +76,42 @@ class traceback "PyTracebackObject *" "&PyTraceback_Type"
7676int
7777_PyTraceback_IsSafeToImport (void )
7878{
79+ // Avoid recursion during critical errors
80+ static int in_safe_to_import = 0 ;
81+ if (in_safe_to_import ) {
82+ return 1 ; // Default to safe during recursion
83+ }
84+ in_safe_to_import = 1 ;
85+
7986 PyObject * sys_path = PySys_GetObject ("path" );
8087 if (sys_path == NULL || !PyList_Check (sys_path ) || PyList_Size (sys_path ) == 0 ) {
88+ in_safe_to_import = 0 ;
8189 return 1 ; // Default to safe
8290 }
8391 PyObject * first_path = PyList_GetItem (sys_path , 0 );
8492 if (first_path == NULL || !PyUnicode_Check (first_path )) {
93+ in_safe_to_import = 0 ;
8594 return 1 ;
8695 }
8796 const char * path_str = PyUnicode_AsUTF8 (first_path );
8897 if (path_str == NULL || strlen (path_str ) == 0 ) {
98+ in_safe_to_import = 0 ;
8999 return 1 ;
90100 }
91101 // Check if traceback.py exists in the first path directory
92102 char traceback_path [MAXPATHLEN ];
93103 int ret = snprintf (traceback_path , sizeof (traceback_path ), "%s/traceback.py" , path_str );
94104 if (ret <= 0 || ret >= (int )sizeof (traceback_path )) {
105+ in_safe_to_import = 0 ;
95106 return 1 ; // Path too long or other error, default to safe
96107 }
97108 FILE * f = fopen (traceback_path , "r" );
98109 if (f != NULL ) {
99110 fclose (f );
111+ in_safe_to_import = 0 ;
100112 return 0 ; // Not safe - traceback.py exists
101113 }
114+ in_safe_to_import = 0 ;
102115 return 1 ; // Safe to import
103116}
104117
You can’t perform that action at this time.
0 commit comments