77#include "pycore_frame.h" // PyFrameObject
88#include "pycore_interp.h" // PyInterpreterState.gc
99#include "pycore_interpframe.h" // _PyFrame_GetCode()
10+ #include "pycore_object.h" // _PyObject_IsFreed()
1011#include "pycore_pyerrors.h" // _PyErr_GetRaisedException()
1112#include "pycore_pystate.h" // _PyThreadState_GET()
1213#include "pycore_traceback.h" // EXCEPTION_TB_HEADER
@@ -898,15 +899,17 @@ dump_char(int fd, char ch)
898899void
899900_Py_DumpASCII (int fd , PyObject * text )
900901{
901- PyASCIIObject * ascii = _PyASCIIObject_CAST (text );
902902 Py_ssize_t i , size ;
903903 int truncated ;
904904 int kind ;
905905 void * data = NULL ;
906906 Py_UCS4 ch ;
907907
908- if (!PyUnicode_Check (text ))
908+ if (_PyObject_IsFreed ( text ) || !PyUnicode_Check (text )) {
909909 return ;
910+ }
911+
912+ PyASCIIObject * ascii = _PyASCIIObject_CAST (text );
910913
911914 size = ascii -> length ;
912915 kind = ascii -> state .kind ;
@@ -1041,21 +1044,25 @@ dump_frame(int fd, _PyInterpreterFrame *frame)
10411044 return -1 ;
10421045 }
10431046
1044- int res = 0 ;
10451047 PUTS (fd , " File " );
1046- if (code -> co_filename != NULL
1047- && PyUnicode_Check (code -> co_filename ))
1048- {
1049- PUTS (fd , "\"" );
1050- _Py_DumpASCII (fd , code -> co_filename );
1051- PUTS (fd , "\"" );
1048+ if (_PyObject_IsFreed ((PyObject * )code ) || !PyCode_Check (code )) {
1049+ PUTS (fd , "???, line ??? in ???\n" );
1050+ return -1 ;
10521051 }
1053- else {
1054- PUTS (fd , "???" );
1055- res = -1 ;
1052+ PyObject * filename = code -> co_filename ;
1053+ if (_PyObject_IsFreed (filename ) || !PyUnicode_Check (filename )) {
1054+ PUTS (fd , "???, line ??? in ???\n" );
1055+ return -1 ;
10561056 }
1057+ PUTS (fd , "\"" );
1058+ _Py_DumpASCII (fd , filename );
1059+ PUTS (fd , "\"" );
10571060
10581061 PUTS (fd , ", line " );
1062+ if (_PyObject_IsFreed ((PyObject * )code ) || !PyCode_Check (code )) {
1063+ PUTS (fd , "??? in ???\n" );
1064+ return -1 ;
1065+ }
10591066 int lasti = _PyFrame_SafeGetLasti (frame );
10601067 int lineno = -1 ;
10611068 if (lasti >= 0 ) {
@@ -1065,20 +1072,23 @@ dump_frame(int fd, _PyInterpreterFrame *frame)
10651072 _Py_DumpDecimal (fd , (size_t )lineno );
10661073 }
10671074 else {
1068- PUTS (fd , "???" );
1069- res = -1 ;
1075+ PUTS (fd , "??? in ???\n " );
1076+ return -1 ;
10701077 }
10711078
10721079 PUTS (fd , " in " );
1073- if (code -> co_name != NULL && PyUnicode_Check (code -> co_name )) {
1074- _Py_DumpASCII (fd , code -> co_name );
1080+ if (_PyObject_IsFreed ((PyObject * )code ) || !PyCode_Check (code )) {
1081+ PUTS (fd , "???\n" );
1082+ return -1 ;
10751083 }
1076- else {
1077- PUTS (fd , "???" );
1078- res = -1 ;
1084+ PyObject * name = code -> co_name ;
1085+ if (_PyObject_IsFreed (name ) || !PyUnicode_Check (name )) {
1086+ PUTS (fd , "???\n" );
1087+ return -1 ;
10791088 }
1089+ _Py_DumpASCII (fd , name );
10801090 PUTS (fd , "\n" );
1081- return res ;
1091+ return 0 ;
10821092}
10831093
10841094static int _Py_NO_SANITIZE_THREAD
0 commit comments