Skip to content
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

gh-96821: Fix undefined behaviour in _testcapimodule.c #96915

Merged
merged 6 commits into from
Sep 19, 2022

Conversation

matthiasgoergens
Copy link
Contributor

@matthiasgoergens matthiasgoergens commented Sep 18, 2022

The first commit demonstrates the undefined behaviour and is meant to fail tests.

The other commits fix it.

@matthiasgoergens matthiasgoergens changed the title gh-96821: Assert for demonstrating undefined behaviour gh-96821: Fix undefined behaviour in _testcapimodule.c Sep 18, 2022
@matthiasgoergens
Copy link
Contributor Author

@kumaraditya303 @mdickinson Would you please have a look?

@CAM-Gerlach CAM-Gerlach added the extension-modules C modules in the Modules dir label Sep 18, 2022
matthiasgoergens and others added 2 commits September 19, 2022 07:42
…e-96821.Co2iOq.rst

Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
Copy link
Member

@Fidget-Spinner Fidget-Spinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I've wrote similar code before elsewhere (just doing raw pointer arithmetic on an unverified args pointer). However, I don't recall where exactly now :(.

Anyways, thanks this LGTM.

@matthiasgoergens
Copy link
Contributor Author

Thanks!

@Fidget-Spinner Fidget-Spinner merged commit cbdeda8 into python:main Sep 19, 2022
@Fidget-Spinner Fidget-Spinner added needs backport to 3.10 only security fixes needs backport to 3.11 only security fixes labels Sep 19, 2022
@miss-islington
Copy link
Contributor

Thanks @matthiasgoergens for the PR, and @Fidget-Spinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Thanks @matthiasgoergens for the PR, and @Fidget-Spinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-96926 is a backport of this pull request to the 3.10 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.10 only security fixes label Sep 19, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 19, 2022
…nGH-96915)

* pythongh-96821: Assert for demonstrating undefined behaviour

* Fix UB

Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
(cherry picked from commit cbdeda8)

Co-authored-by: Matthias Görgens <matthias.goergens@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 19, 2022
…nGH-96915)

* pythongh-96821: Assert for demonstrating undefined behaviour

* Fix UB

Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
(cherry picked from commit cbdeda8)

Co-authored-by: Matthias Görgens <matthias.goergens@gmail.com>
@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Sep 19, 2022
@bedevere-bot
Copy link

GH-96927 is a backport of this pull request to the 3.11 branch.

@matthiasgoergens
Copy link
Contributor Author

I think I've wrote similar code before elsewhere (just doing raw pointer arithmetic on an unverified args pointer). However, I don't recall where exactly now :(.

There was an example of this in eg ceval.c. Not sure if that one was yours?

Btw, this kind of null pointer arithmetic is perfectly defined, as long as we compile with -fwrapv. I'm just working on cleaning things up so we can get rid of that flag and enjoy a few more C compiler optimisations.

Fidget-Spinner pushed a commit that referenced this pull request Sep 19, 2022
…H-96926)

* gh-96821: Assert for demonstrating undefined behaviour

* Fix UB

(cherry picked from commit cbdeda8)

Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
Co-authored-by: Matthias Görgens <matthias.goergens@gmail.com>
Fidget-Spinner pushed a commit that referenced this pull request Sep 19, 2022
…H-96927)

* gh-96821: Assert for demonstrating undefined behaviour

* Fix UB

(cherry picked from commit cbdeda8)

Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
Co-authored-by: Matthias Görgens <matthias.goergens@gmail.com>
pablogsal pushed a commit that referenced this pull request Oct 24, 2022
…H-96927)

* gh-96821: Assert for demonstrating undefined behaviour

* Fix UB

(cherry picked from commit cbdeda8)

Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
Co-authored-by: Matthias Görgens <matthias.goergens@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extension-modules C modules in the Modules dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants