8000 gh-99110: Initialize frame->previous in init_frame to fix segmentation fault by byllyfish · Pull Request #100182 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-99110: Initialize frame->previous in init_frame to fix segmentation fault #100182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Dec 23, 2022
Prev Previous commit
Next Next commit
Move initialization of frame->previous to init_frame.
Use self.assertEquals instead of assert.
  • Loading branch information
byllyfish committed Dec 13, 2022
commit d6797833bcb0fb6195de0fb23b4c2643122af69f
2 changes: 1 addition & 1 deletion Include/internal/pycore_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ _PyFrame_InitializeSpecials(
frame->f_locals = locals;
frame->stacktop = code->co_nlocalsplus;
frame->frame_obj = NULL;
frame->previous = NULL;
frame->prev_instr = _PyCode_CODE(code) - 1;
frame->yield_offset = 0;
frame->owner = FRAME_OWNED_BY_THREAD;
// frame->previous: initialized when frame is linked into the frame stack
}

/* Gets the pointer to the locals array
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_ctypes/test_python_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def dummy():
)

# The following line should not cause a segmentation fault.
assert frame.f_back is None
self.assertEqual(frame.f_back, None)


if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Initialize frame->previous in _PyFrame_InitializeSpecials.
Initialize frame->previous in frameobject.c to fix a segmentation fault when
accessing frames created by ctypes.