This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Segmentation fault of PyState_AddModule()
Type: enhancement Stage: resolved
Components: C API Versions: Python 3.10
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: shihai1991 Nosy List: petr.viktorin, shihai1991, vstinner
Priority: normal Keywords: patch

Created on 2020-12-12 15:09 by shihai1991, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 23745 closed shihai1991, 2020-12-12 15:23
Messages (5)
msg382915 - (view) Author: Hai Shi (shihai1991) * (Python triager) Date: 2020-12-12 15:09
PyState_AddModule(NULL, &_testcapimodule) in _testcapi module will get a segmentation fault. And it's a C API, so a little improvement will be better.
msg382919 - (view) Author: Petr Viktorin (petr.viktorin) * (Python committer) Date: 2020-12-12 18:50
When does this actually happen? Is there a common situation where you'd mistakenly pass NULL to PyState_AddModule?
msg382934 - (view) Author: Hai Shi (shihai1991) * (Python triager) Date: 2020-12-13 16:00
> When does this actually happen? Is there a common situation where you'd mistakenly pass NULL to PyState_AddModule?

If created mod haven't been checked will have this risk. PyState_AddModule
is a exposing C API, we should make sure that calling API is in a safe way(not raising a segmentation fault). :)
msg383230 - (view) Author: Hai Shi (shihai1991) * (Python triager) Date: 2020-12-17 11:05
Thanks victor, petr for your comment and review. I closed this bpo and PR.

I paste victor's explanation in here in case other developers have the same question too: Getting a crash is the
expected behaviour if you don't respect a function API. Most C
functions are designed like that. Only very few functions check their
arguments, tests are usually omitted for best performances.

Sorry for this noisy bpo.
msg383972 - (view) Author: Petr Viktorin (petr.viktorin) * (Python committer) Date: 2020-12-29 10:20
Thanks, Victor, for explaining!


You'll also see NULL checks in existing code where they aren't strictly necessary, but removing them would be too much trouble.
History
Date User Action Args
2022-04-11 14:59:39adminsetgithub: 86791
2020-12-29 10:20:22petr.viktorinsetmessages: + msg383972
2020-12-17 11:05:50shihai1991setstatus: open -> closed
resolution: rejected
messages: + msg383230

stage: patch review -> resolved
2020-12-13 16:00:48shihai1991setmessages: + msg382934
2020-12-12 18:50:21petr.viktorinsetmessages: + msg382919
2020-12-12 15:23:48shihai1991setkeywords: + patch
stage: patch review
pull_requests: + pull_request22603
2020-12-12 15:09:41shihai1991create