Skip to content

Commit

Permalink
Fix crash if Python frame filename is NULL
Browse files Browse the repository at this point in the history
For Python functions created at runtime, there is no associated
filename, in which case the filename can be NULL. There was code in
ctau_impl.c that assumed the filename was not NULL. This fixes the issue
by using the empty string for the filename if the filename is NULL.


Former-commit-id: 32e2abe04bd4029bbc9e2e67ee0c31efbf5a832b
  • Loading branch information
nchaimov committed Oct 17, 2023
1 parent 5740f06 commit 3ef80df
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Profile/ctau_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,17 +444,19 @@ static ProfilerEntry *newProfilerEntry(ProfilerObject *pObj, void *key, PyObject
PyCodeObject * codeObj = PyFrame_GetCode(frame);
co_name = PyString_AsString(codeObj->co_name);
co_filename = PyString_AsString(codeObj->co_filename);
if(co_filename == NULL) {
co_filename = "";
}
while (strchr(co_filename,'/')) {
co_filename = strchr(co_filename,'/')+1;
co_filename = strchr(co_filename,'/')+1;
}
co_firstlineno = codeObj->co_firstlineno;
sprintf (routine,"%s [{%s}{%d}]", co_name, co_filename, co_firstlineno);
if (strcmp(co_filename,"<string>") != 0) { // suppress "? <string>"
TAU_PROFILER_CREATE(handle, routine, "", TAU_PYTHON);
TAU_PROFILER_CREATE(handle, routine, "", TAU_PYTHON);
}
} else {
if (strcmp (cname, "profileTimer") && strcmp (cname, "start") && strcmp (cname, "stop") && strcmp (cname, "disable")) {
/* sprintf (routine,"C [%s]", cname); */
sprintf (routine,"%s", cname);
TAU_PROFILER_CREATE(handle, routine, "", TAU_PYTHON);
}
Expand Down

0 comments on commit 3ef80df

Please sign in to comment.