GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-99240: Reset pointer to NULL when the pointed memory is freed in argument parsing by colorfulappl · Pull Request #99890 · python/cpython

Conversation

@colorfulappl

@colorfulappl colorfulappl commented Nov 30, 2022 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

In the family of _PyArg_Parse functions, pointers can be passed in as arguments to store the parsed PyArgs.
If a pointer is assigned to newly allocated memory and the memory is freed as a result of an error while parsing the subsequent PyArgs, the pointer should be set to NULL; otherwise, it leaks the freed memory.

  • Issue: Double-free in Argument Clinic str_converter generated code #99240

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

erlend-aasland reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
colorfulappl added 2 commits November 30, 2022 16:42
@colorfulappl
Reset pointer to NULL when memory is freed
9271e85
@colorfulappl
Add news
eba62a3
@bedevere-bot bedevere-bot mentioned this pull request Nov 30, 2022
Double-free in Argument Clinic str_converter generated code #99240
Closed
@bedevere-bot bedevere-bot added the awaiting review label Nov 30, 2022
@colorfulappl

colorfulappl commented Nov 30, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

This fix corresponds to my comment in #99240

If function _PyArg_ParseStack parses failed, assign all the parsed arguments to "NULL" after they are freed, this should be done in _PyArg_ParseStack.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

kumaraditya303
kumaraditya303 reviewed Dec 13, 2022
View reviewed changes
Comment thread Python/getargs.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@colorfulappl
Remove unnecessary null-check
39895ee
@python python deleted a comment from netlify Bot Dec 14, 2022
@kumaraditya303

kumaraditya303 commented Dec 14, 2022

Copy link
Copy Markdown
Contributor

Can you add a test for this?

colorfulappl reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@colorfulappl
Add test
ef866b2
kumaraditya303
kumaraditya303 reviewed Dec 15, 2022
View reviewed changes
Comment thread Modules/_testcapi/getargs.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@carljm carljm changed the title gh-99240: Reset pointer to NULL then the pointed memory is freed in argument parsing gh-99240: Reset pointer to NULL when the pointed memory is freed in argument parsing Dec 15, 2022
@colorfulappl
Fix an error
357576b
kumaraditya303
kumaraditya303 reviewed Dec 16, 2022
View reviewed changes
Comment thread Modules/_testcapi/getargs.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@kumaraditya303
PyMem_FREE -> PyMem_Free
0424701
kumaraditya303
kumaraditya303 reviewed Dec 16, 2022
View reviewed changes
Comment thread Modules/_testcapi/getargs.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

kumaraditya303 added 2 commits December 16, 2022 16:26
@kumaraditya303
Update Modules/_testcapi/getargs.c
4a7d386
@kumaraditya303
Merge branch 'main' into clear_freed_pointer
1d3b069
@kumaraditya303 kumaraditya303 self-assigned this Dec 16, 2022
kumaraditya303
kumaraditya303 approved these changes Dec 16, 2022
View reviewed changes

@kumaraditya303 kumaraditya303 left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting review labels Dec 16, 2022
@kumaraditya303 kumaraditya303 added needs backport to 3.10 needs backport to 3.11 only security fixes labels Dec 16, 2022
@kumaraditya303
kumaraditya303 requested a review from erlend-aasland December 16, 2022 11:03
erlend-aasland
erlend-aasland approved these changes Dec 16, 2022
View reviewed changes
Comment thread Modules/_testcapi/getargs.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@erlend-aasland
Update Modules/_testcapi/getargs.c
6e9744c
kumaraditya303
kumaraditya303 approved these changes Dec 17, 2022
View reviewed changes
@kumaraditya303
kumaraditya303 merged commit a6f82f1 into python:main Dec 17, 2022
@bedevere-bot bedevere-bot removed the awaiting merge label Dec 17, 2022
@miss-islington

miss-islington commented Dec 17, 2022

Copy link
Copy Markdown
Contributor

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington

miss-islington commented Dec 17, 2022

Copy link
Copy Markdown
Contributor

Sorry, @colorfulappl and @kumaraditya303, I could not cleanly backport this to 3.11 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker a6f82f1fc68cb24e2d88d35fde4cfb663213a744 3.11

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington

miss-islington commented Dec 17, 2022

Copy link
Copy Markdown
Contributor

Sorry, @colorfulappl and @kumaraditya303, I could not cleanly backport this to 3.10 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker a6f82f1fc68cb24e2d88d35fde4cfb663213a744 3.10

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@kumaraditya303

kumaraditya303 commented Dec 17, 2022

Copy link
Copy Markdown
Contributor

@colorfulappl Can you create the backport PRs? Thanks

colorfulappl reacted with laugh emoji
All reactions
  • 😄 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

kumaraditya303 added a commit to kumaraditya303/cpython that referenced this pull request Dec 17, 2022
@colorfulappl @kumaraditya303 @erlend-aasland
pythongh-99240: Reset pointer to NULL when the pointed memory is free…
efbb1eb
…d in argument parsing (python#99890)

Co-authored-by: Kumar Aditya <[email protected]>
Co-authored-by: Erlend E. Aasland <[email protected]>
shihai1991 added a commit to shihai1991/cpython that referenced this pull request Dec 18, 2022
@shihai1991
Merge remote-tracking branch 'origin/main' into bpo_34697
2878571
* origin/main: (1306 commits)
  Correct CVE-2020-10735 documentation (python#100306)
  pythongh-100272: Fix JSON serialization of OrderedDict (pythonGH-100273)
  pythongh-93649: Split tracemalloc tests from _testcapimodule.c (python#99551)
  Docs: Use `PY_VERSION_HEX` for version comparison (python#100179)
  pythongh-97909: Fix markup for `PyMethodDef` members (python#100089)
  pythongh-99240: Reset pointer to NULL when the pointed memory is freed in argument parsing (python#99890)
  pythongh-99240: Reset pointer to NULL when the pointed memory is freed in argument parsing (python#99890)
  pythonGH-98831: Add DECREF_INPUTS(), expanding to DECREF() each stack input (python#100205)
  pythongh-78707: deprecate passing >1 argument to `PurePath.[is_]relative_to()` (pythonGH-94469)
  pythongh-99540: Constant hash for _PyNone_Type to aid reproducibility (pythonGH-99541)
  pythongh-100039: enhance __signature__ to work with str and callables (pythonGH-100168)
  pythongh-99830: asyncio: Document returns of remove_{reader,writer} (python#100302)
  "Compound statement" docs: Fix with-statement step indexing (python#100286)
  pythonGH-90043: Handle NaNs in COMPARE_OP_FLOAT_JUMP (pythonGH-100278)
  Improve stats presentation for calls. (pythonGH-100274)
  Better stats for `LOAD_ATTR` and `STORE_ATTR` (pythonGH-100295)
  pythongh-81057: Move the Cached Parser Dummy Name to _PyRuntimeState (python#100277)
  Document that zipfile's pwd parameter is a `bytes` object (python#100209)
  pythongh-99767: mark `PyTypeObject.tp_watched` as internal use only in table (python#100271)
  Fix typo in introduction.rst (python#100266)
  ...
@colorfulappl

colorfulappl commented Dec 19, 2022

Copy link
Copy Markdown
Contributor Author

@colorfulappl Can you create the backport PRs?

Sure. I will do this later.

erlend-aasland reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

carljm added a commit to carljm/cpython that referenced this pull request Dec 19, 2022
@carljm
Merge branch 'main' into fastmock
a9af20a
* main:
  pythongh-89727: Fix os.walk RecursionError on deep trees (python#99803)
  Docs: Don't upload CI artifacts (python#100330)
  pythongh-94912: Added marker for non-standard coroutine function detection (python#99247)
  Correct CVE-2020-10735 documentation (python#100306)
  pythongh-100272: Fix JSON serialization of OrderedDict (pythonGH-100273)
  pythongh-93649: Split tracemalloc tests from _testcapimodule.c (python#99551)
  Docs: Use `PY_VERSION_HEX` for version comparison (python#100179)
  pythongh-97909: Fix markup for `PyMethodDef` members (python#100089)
  pythongh-99240: Reset pointer to NULL when the pointed memory is freed in argument parsing (python#99890)
  pythongh-99240: Reset pointer to NULL when the pointed memory is freed in argument parsing (python#99890)
  pythonGH-98831: Add DECREF_INPUTS(), expanding to DECREF() each stack input (python#100205)
  pythongh-78707: deprecate passing >1 argument to `PurePath.[is_]relative_to()` (pythonGH-94469)
colorfulappl added a commit to colorfulappl/cpython that referenced this pull request Dec 21, 2022
@colorfulappl @kumaraditya303 @erlend-aasland
[3.11] pythongh-99240: Reset pointer to NULL when the pointed memory …
62c4a95
…is freed in argument parsing (pythonGH-99890)

(cherry picked from commit efbb1eb)

Co-authored-by: Kumar Aditya <[email protected]>
Co-authored-by: Erlend E. Aasland <[email protected]>
@bedevere-bot

bedevere-bot commented Dec 21, 2022

Copy link
Copy Markdown

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Dec 21, 2022
colorfulappl added a commit to colorfulappl/cpython that referenced this pull request Dec 21, 2022
@colorfulappl @kumaraditya303 @erlend-aasland
[3.10] pythongh-99240: Reset pointer to NULL when the pointed memory …
e02b61b
…is freed in argument parsing (pythonGH-99890)

(cherry picked from commit efbb1eb)

Co-authored-by: Kumar Aditya <[email protected]>
Co-authored-by: Erlend E. Aasland <[email protected]>
@bedevere-bot

bedevere-bot commented Dec 21, 2022

Copy link
Copy Markdown

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the needs backport to 3.10 label Dec 21, 2022
kumaraditya303 added a commit that referenced this pull request Dec 21, 2022
@colorfulappl @kumaraditya303 @erlend-aasland
[3.11] gh-99240: Reset pointer to NULL when the pointed memory is fre…
bed1d14
…ed in argument parsing (GH-99890) (#100385)

(cherry picked from commit efbb1eb)

Co-authored-by: Kumar Aditya <[email protected]>
Co-authored-by: Erlend E. Aasland <[email protected]>
kumaraditya303 added a commit that referenced this pull request Dec 21, 2022
@colorfulappl @kumaraditya303 @erlend-aasland
[3.10] gh-99240: Reset pointer to NULL when the pointed memory is fre…
591365c
…ed in argument parsing (GH-99890) (#100386)

(cherry picked from commit efbb1eb)

Co-authored-by: Kumar Aditya <[email protected]>
Co-authored-by: Erlend E. Aasland <[email protected]>
rwgk pushed a commit to rwgk/cpython that referenced this pull request Mar 11, 2023
@colorfulappl @kumaraditya303
@erlend-aasland @rwgk
pythongh-99240: Reset pointer to NULL when the pointed memory is free…
9aad32a
…d in argument parsing (python#99890)

Co-authored-by: Kumar Aditya <[email protected]>
Co-authored-by: Erlend E. Aasland <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@erlend-aasland erlend-aasland erlend-aasland approved these changes
@kumaraditya303 kumaraditya303 kumaraditya303 approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@kumaraditya303 kumaraditya303

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@colorfulappl @kumaraditya303 @miss-islington @bedevere-bot @erlend-aasland
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.