diff --git a/ddtrace/appsec/_iast/_stacktrace.c b/ddtrace/appsec/_iast/_stacktrace.c index 893d2c5a076..057e9d5a803 100644 --- a/ddtrace/appsec/_iast/_stacktrace.c +++ b/ddtrace/appsec/_iast/_stacktrace.c @@ -9,6 +9,7 @@ static __thread int in_stacktrace = 0; #include #include #include +#include #ifdef _WIN32 #define DD_TRACE_INSTALLED_PREFIX "\\ddtrace\\" @@ -25,6 +26,7 @@ static __thread int in_stacktrace = 0; #define GET_LINENO(frame) PyFrame_GetLineNumber((PyFrameObject*)frame) #define GET_FRAME(tstate) PyThreadState_GetFrame(tstate) #define GET_PREVIOUS(frame) PyFrame_GetBack(frame) +#define FRAME_INCREF(frame) Py_INCREF((PyObject*)frame) #define FRAME_DECREF(frame) Py_DecRef((PyObject*)frame) #define FRAME_XDECREF(frame) Py_XDECREF((PyObject*)frame) #define FILENAME_DECREF(filename) Py_DecRef(filename) @@ -68,6 +70,7 @@ GET_FUNCTION(PyFrameObject* frame) #define GET_FRAME(tstate) tstate->frame #define GET_PREVIOUS(frame) frame->f_back #define GET_FILENAME(frame) ((PyObject*)(frame->f_code->co_filename)) +#define FRAME_INCREF(frame) #define FRAME_DECREF(frame) #define FRAME_XDECREF(frame) #define FILENAME_DECREF(filename) @@ -88,6 +91,14 @@ GET_FUNCTION(PyFrameObject* frame) #endif #endif +// Python standard library path +static char* STDLIB_PATH = NULL; +static ssize_t STDLIB_PATH_LEN = 0; + +// Python site-packages path +static char* PURELIB_PATH = NULL; +static ssize_t PURELIB_PATH_LEN = 0; + static inline PyObject* SAFE_GET_LOCALS(PyFrameObject* frame) { @@ -121,115 +132,191 @@ GET_CLASS(PyFrameObject* frame) } /** - * get_file_and_line - * - * Get the filename, line number, function name and class name of the original wrapped - * function to report it. - * - * Returns a tuple: - * (filename, line_number, function name, class name) - **/ -static PyObject* -get_file_and_line(PyObject* Py_UNUSED(module), PyObject* cwd_obj) + * Checks if the filename is special. + * For example, a frozen module (``), a template (`