Skip to content

gh-126238: Fix possible null pointer dereference of freevars in _PyCompile_LookupArg#126239

Merged
sobolevn merged 4 commits into
python:mainfrom
federicovalenso:bug/possible-null-pointer-dereference-in-_PyCompile_LookupArg
Nov 5, 2024
Merged

gh-126238: Fix possible null pointer dereference of freevars in _PyCompile_LookupArg#126239
sobolevn merged 4 commits into
python:mainfrom
federicovalenso:bug/possible-null-pointer-dereference-in-_PyCompile_LookupArg

Conversation

@federicovalenso

@federicovalenso federicovalenso commented Oct 31, 2024

Copy link
Copy Markdown
Contributor

@bedevere-app

bedevere-app Bot commented Oct 31, 2024

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@federicovalenso federicovalenso marked this pull request as ready for review October 31, 2024 13:15
Comment thread Misc/NEWS.d/next/Security/2024-10-31-13-14-27.gh-issue-126238.CZqaon.rst Outdated

@iritkatriel iritkatriel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we cover this with a test?

@ZeroIntensity

Copy link
Copy Markdown
Member

I'm not exactly sure how to trigger it, it was found via a static analyzer.

…CZqaon.rst

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
@@ -0,0 +1 @@
Fix a possible crash internally when compiling.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I suggest to drop this NEWS entry.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I concur (that's what I did for #126241 because it's a bit hard to phrase it properly and meaningfully).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

drop this NEWS entry

Done )

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why? This seems user-facing to me, isn't it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@sobolevn, @picnixz , what's the bottom line? Is news entry required or not?

@picnixz picnixz Nov 1, 2024

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The bottom line in general is whether this kind of bug can be triggered easily using public interface. Unless you have a reproducer saying that with X and Y you can do Z, or unless the interface is publicly documented and known to the outside world, a NEWS entry would be fine. But here, we have neither a test nor is _PyCompile_LookupArg something that is exposed to the world.

As an end-user, reading "Fix a possible crash internally when compiling." gives me no information at all except that there was a bug I wasn't aware of (and that it was not always triggerable). I don't know how to make the crash happen, nor do I know what was crashing.

@picnixz picnixz added needs backport to 3.12 only security fixes needs backport to 3.13 bugs and security fixes skip news labels Oct 31, 2024
Comment thread Python/compile.c
@@ -901,7 +901,7 @@ _PyCompile_LookupArg(compiler *c, PyCodeObject *co, PyObject *name)
c->u->u_metadata.u_name,
co->co_name,
freevars);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does PyErr_Format work for null?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, %R formats it as "<NULL>"

@ruidazeng

Copy link
Copy Markdown

I'm not exactly sure how to trigger it, it was found via a static analyzer.

Can you be more specific? I cannot reproduce this internal crash.

@ZeroIntensity

Copy link
Copy Markdown
Member

Can you be more specific? I cannot reproduce this internal crash.

See GH-126238. Looking at the source, this can only fail in some rare cases when a memory allocation fails, but it's pretty clearly wrong if that was the case so we might as well fix it.

@ZeroIntensity ZeroIntensity left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm happy with it.

@sobolevn sobolevn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you, congrats on your first merged PR :)

@sobolevn sobolevn merged commit 8525c93 into python:main Nov 5, 2024
@miss-islington-app

Copy link
Copy Markdown

Thanks @federicovalenso for the PR, and @sobolevn for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Sorry, @federicovalenso and @sobolevn, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 8525c9375f25e6ec0c0b5dfcab464703f6e78082 3.13

@miss-islington-app

Copy link
Copy Markdown

Sorry, @federicovalenso and @sobolevn, I could not cleanly backport this to 3.12 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 8525c9375f25e6ec0c0b5dfcab464703f6e78082 3.12

@sobolevn

sobolevn commented Nov 5, 2024

Copy link
Copy Markdown
Member

@ZeroIntensity

Copy link
Copy Markdown
Member

See the devguide if you want to know how to do that.

@federicovalenso

Copy link
Copy Markdown
Contributor Author

@sobolevn , @ZeroIntensity , I'll try to do that)

federicovalenso added a commit to federicovalenso/cpython that referenced this pull request Nov 6, 2024
…vars in _PyCompile_LookupArg (pythonGH-126239)

* Replace Py_DECREF by Py_XDECREF

(cherry picked from commit 8525c93)

Co-authored-by: Valery Fedorenko <federicovalenso@gmail.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
@federicovalenso

federicovalenso commented Nov 6, 2024

Copy link
Copy Markdown
Contributor Author

@sobolevn , could you please look at #126474, #126475 )

federicovalenso added a commit to federicovalenso/cpython that referenced this pull request Nov 6, 2024
…vars in _PyCompile_LookupArg (pythonGH-126239)

* Replace Py_DECREF by Py_XDECREF

(cherry picked from commit 8525c93)

Co-authored-by: Valery Fedorenko <federicovalenso@gmail.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
sobolevn pushed a commit that referenced this pull request Nov 6, 2024
…e_LookupArg (gh-126238) (#126474)

[3.12] gh-126238: Fix possible null pointer dereference of freevars in _PyCompile_LookupArg (GH-126239)

* Replace Py_DECREF by Py_XDECREF

(cherry picked from commit 8525c93)

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
sobolevn pushed a commit that referenced this pull request Nov 6, 2024
…e_LookupArg (gh-126238) (#126475)

[3.13] gh-126238: Fix possible null pointer dereference of freevars in _PyCompile_LookupArg (GH-126239)

* Replace Py_DECREF by Py_XDECREF

(cherry picked from commit 8525c93)

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
@ambv ambv removed needs backport to 3.12 only security fixes needs backport to 3.13 bugs and security fixes labels Nov 12, 2024
picnixz pushed a commit to picnixz/cpython that referenced this pull request Dec 8, 2024
… _PyCompile_LookupArg (python#126239)

* Replace Py_DECREF by Py_XDECREF

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
ebonnal pushed a commit to ebonnal/cpython that referenced this pull request Jan 12, 2025
… _PyCompile_LookupArg (python#126239)

* Replace Py_DECREF by Py_XDECREF

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants