Thanks to visit codestin.com
Credit goes to github.com

Skip to content

bpo-34824: Fix a possible NULL pointer dereference in _ssl.c #9606

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

Merged
merged 4 commits into from
Oct 6, 2018

Conversation

ZackerySpytz
Copy link
Contributor

@ZackerySpytz ZackerySpytz commented Sep 27, 2018

On failure, _PyBytes_Resize() will deallocate the bytes object and set
"result" to NULL.

https://bugs.python.org/issue34824

On failure, _PyBytes_Resize() will deallocate the bytes object and set
"result" to NULL.
Copy link
Member

@tiran tiran left a comment

Choose a reason for hiding this comment

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

Good catch!

Please address the comment.

Modules/_ssl.c Outdated
@@ -4712,7 +4712,6 @@ _ssl_MemoryBIO_read_impl(PySSLMemoryBIO *self, int len)
nbytes = BIO_read(self->bio, PyBytes_AS_STRING(result), len);
/* There should never be any short reads but check anyway. */
if ((nbytes < len) && (_PyBytes_Resize(&result, len) < 0)) {
Py_DECREF(result);
Copy link
Member

Choose a reason for hiding this comment

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

Let's rewrite the block to conform to the style of other _PyBytes_Resize calls. There is no need to check the return value of _PyBytes_Resize, because the function returns result any way.

if (nbytes < len) {
    _PyBytes_Resize(&result, len);
}

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@ZackerySpytz
Copy link
Contributor Author

I have made the requested changes; please review again.

@bedevere-bot
Copy link

Thanks for making the requested changes!

@1st1, @tiran: please review the changes made to this pull request.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

The current code doesn't have any effect and errors in BIO_read() are not handled.

Modules/_ssl.c Outdated
Py_DECREF(result);
return NULL;
if (nbytes < len) {
_PyBytes_Resize(&result, len);
Copy link
Member

Choose a reason for hiding this comment

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

This operation doesn't have any effect. There should be nbytes instead of len. Note that nbytes can be negative, this denotes an error.

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@ZackerySpytz
Copy link
Contributor Author

I have made the requested changes; please review again.

@bedevere-bot
Copy link

Thanks for making the requested changes!

@serhiy-storchaka, @1st1, @tiran: please review the changes made to this pull request.

if ((nbytes < len) && (_PyBytes_Resize(&result, len) < 0)) {
Py_DECREF(result);
if (nbytes < 0) {
_setSSLError(NULL, 0, __FILE__, __LINE__);
return NULL;
Copy link
Member

Choose a reason for hiding this comment

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

result is leaked here.

@ZackerySpytz
Copy link
Contributor Author

I have made the requested changes; please review again.

@bedevere-bot
Copy link

Thanks for making the requested changes!

@tiran, @serhiy-storchaka, @1st1: please review the changes made to this pull request.

@miss-islington miss-islington merged commit 365ad2e into python:master Oct 6, 2018
@miss-islington
Copy link
Contributor

Thanks @ZackerySpytz for the PR 🌮🎉.. I'm working now to backport this PR to: 3.6, 3.7.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 6, 2018
…H-9606)

On failure, _PyBytes_Resize() will deallocate the bytes object and set
"result" to NULL.

https://bugs.python.org/issue34824
(cherry picked from commit 365ad2e)

Co-authored-by: Zackery Spytz <[email protected]>
@bedevere-bot
Copy link

GH-9743 is a backport of this pull request to the 3.7 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 6, 2018
…H-9606)

On failure, _PyBytes_Resize() will deallocate the bytes object and set
"result" to NULL.

https://bugs.python.org/issue34824
(cherry picked from commit 365ad2e)

Co-authored-by: Zackery Spytz <[email protected]>
@bedevere-bot
Copy link

GH-9744 is a backport of this pull request to the 3.6 branch.

vstinner pushed a commit that referenced this pull request Oct 19, 2018
GH-9743)

On failure, _PyBytes_Resize() will deallocate the bytes object and set
"result" to NULL.

https://bugs.python.org/issue34824
(cherry picked from commit 365ad2e)

Co-authored-by: Zackery Spytz <[email protected]>
vstinner pushed a commit that referenced this pull request Oct 19, 2018
GH-9744)

On failure, _PyBytes_Resize() will deallocate the bytes object and set
"result" to NULL.

https://bugs.python.org/issue34824
(cherry picked from commit 365ad2e)

Co-authored-by: Zackery Spytz <[email protected]>
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.

7 participants