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-96678: Fix UB of null pointer arithmetic #96782

Merged
merged 4 commits into from
Sep 13, 2022

Conversation

matthiasgoergens
Copy link
Contributor

@matthiasgoergens matthiasgoergens commented Sep 13, 2022

Automerge-Triggered-By: GH:pablogsal

@matthiasgoergens matthiasgoergens changed the title gh-96678: Assert for avoidance of undefined behaviour gh-96678: Fix UB of null pointer arithmetic Sep 13, 2022
Copy link
Member

@pablogsal pablogsal left a comment

Choose a reason for hiding this comment

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

Have the assert ever triggered in the test suite? Do you have the stack trace at that point?

@pablogsal
Copy link
Member

Also can you add a news entry?

@matthiasgoergens
Copy link
Contributor Author

matthiasgoergens commented Sep 13, 2022

Have the assert ever triggered in the test suite? Do you have the stack trace at that point?

Yes, the assert triggers in the test suite. You can see ths when you look at the build bot's test run for that commit. I don't know whether that build bot gives a stack trace, though.

I can try to give you stack trace.

@pablogsal
Copy link
Member

Have the assert ever triggered in the test suite? Do you have the stack trace at that point?

Yes, the assert triggers in the test suite. You can see ths when you look at the build bot's test run for that commit. I don't know whether that build bot ein gives so a stack trace, though.

I can try to give you stack trace.

No need, just add the NEWS entry and I can land this. Interestingly this code has been here since the beginning of time :P

@pablogsal
Copy link
Member

pablogsal commented Sep 13, 2022

Ah, but this should have been detected by the UB buildbot no? This means that it happens only in a subprocess or there is some shenanigans again that prevent this to surface in release mode

@pablogsal
Copy link
Member

pablogsal commented Sep 13, 2022

Ah, indeed. All failures happen in subprocesses. But this should be detected by the buildbot in any case I think.

@matthiasgoergens
Copy link
Contributor Author

Ah, but this should have been detected by the UB buildbot no? This means that it happens only in a subprocess or there is some shenanigans again that prevent this to surface in release mode

I explained the shenanigans in the last comment on the issue.

Basically, it's only undefined behaviour in standard C.

We are using -fwrapv which makes it defined behaviour. That's why the sanitiser doesn't complain.

My goal here to clean this up anyway, so we can consider running without -fwrapv, and perhaps get a few more C compiler optimisations.thst way.

@pablogsal
Copy link
Member

We are using -fwrapv which makes it defined behaviour. That's why the sanitiser doesn't complain.

But for this case we need -fwrapv-pointer. I assume that's also passed in release mode?

@pablogsal
Copy link
Member

In any case, I am landing the PR. Thanks a lot for working on this. Your work really makes a difference ❤️

@matthiasgoergens
Copy link
Contributor Author

Just from reading the compiler docs, I would agree.

But in practice, -fwrapv seems to be enough for some reason.

@matthiasgoergens
Copy link
Contributor Author

My goal is to make it so that we can run with -fstrict-overflow (if we want to.)

@matthiasgoergens
Copy link
Contributor Author

@pablogsal faster-cpython/ideas#458 might be interesting for you in this context.

@kumaraditya303
Copy link
Contributor

The bot isn't merging this because 'awaiting review' was added mistakenly, I am fixing the labels.

@miss-islington
Copy link
Contributor

Thanks @matthiasgoergens for the PR 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 13, 2022
Automerge-Triggered-By: GH:pablogsal
(cherry picked from commit 81e36f3)

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

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

@bedevere-bot
Copy link

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

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 13, 2022
Automerge-Triggered-By: GH:pablogsal
(cherry picked from commit 81e36f3)

Co-authored-by: Matthias Görgens <matthias.goergens@gmail.com>
miss-islington added a commit that referenced this pull request Sep 13, 2022
Automerge-Triggered-By: GH:pablogsal
(cherry picked from commit 81e36f3)

Co-authored-by: Matthias Görgens <matthias.goergens@gmail.com>
miss-islington added a commit that referenced this pull request Sep 13, 2022
Automerge-Triggered-By: GH:pablogsal
(cherry picked from commit 81e36f3)

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
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants