Skip to content

Commit

Permalink
fix: null array indexing in CTracer_handle_return (#1843)
Browse files Browse the repository at this point in the history
CTracer_set_pdata_stack can initialize self.pdata_stack to an empty
stack where ->stack is NULL and ->deph is -1.

Move index into ->stack into ->depth>=0 check to avoid indexing into
NULL array.

This issue was found running UndefinedBehaviourSanitizer. It's
reproducible in regular test runs, e.g. `python3 -m tox -e py311`.
Adding `if (self->pdata_stack->stack == NULL) { fprint(...) }` before
the moved line shows the issue in several test cases.
  • Loading branch information
frigus02 committed Sep 3, 2024
1 parent 28d22a3 commit f4c1f01
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion coverage/ctracer/tracer.c
Original file line number Diff line number Diff line change
Expand Up @@ -722,9 +722,9 @@ CTracer_handle_return(CTracer *self, PyFrameObject *frame)
if (CTracer_set_pdata_stack(self) < 0) {
goto error;
}
self->pcur_entry = &self->pdata_stack->stack[self->pdata_stack->depth];

if (self->pdata_stack->depth >= 0) {
self->pcur_entry = &self->pdata_stack->stack[self->pdata_stack->depth];
if (self->tracing_arcs && self->pcur_entry->file_data) {
BOOL real_return = FALSE;
pCode = MyCode_GetCode(MyFrame_GetCode(frame));
Expand Down

0 comments on commit f4c1f01

Please sign in to comment.