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

Unreachable code in Modules/_ssl.c #106831

Closed
sobolevn opened this issue Jul 17, 2023 · 1 comment
Closed

Unreachable code in Modules/_ssl.c #106831

sobolevn opened this issue Jul 17, 2023 · 1 comment
Assignees
Labels
topic-SSL type-bug An unexpected behavior, bug, or error

Comments

@sobolevn
Copy link
Member

sobolevn commented Jul 17, 2023

Looks like code in this check cannot ever be reached:

cpython/Modules/_ssl.c

Lines 2824 to 2827 in 2b94a05

newsession = d2i_SSL_SESSION(NULL, &const_p, slen);
if (session == NULL) {
goto error;
}

At this point session cannot be NULL, because it is checked right above:

cpython/Modules/_ssl.c

Lines 2803 to 2806 in 2b94a05

if (session == NULL) {
PyErr_SetString(PyExc_ValueError, "Invalid session");
goto error;
}

I guess that it was intended to check newsession variable instead.

Docs say: https://www.openssl.org/docs/man1.0.2/man3/d2i_SSL_SESSION.html

d2i_SSL_SESSION() returns a pointer to the newly allocated SSL_SESSION object. In case of failure the NULL-pointer is returned and the error message can be retrieved from the error stack.

One more thing that bothers me here is that error is not set. We just return NULL which can theoretically crash the interpeter.

So, my plan is to:

  1. Check newsession instead
  2. Add a ValueError there

Originally introduced in 99a6570

PR is on its way.

Found by Linux Verification Center (portal.linuxtesting.ru) with SVACE.

Author A. Voronin.

Linked PRs

@sobolevn sobolevn added type-bug An unexpected behavior, bug, or error topic-SSL labels Jul 17, 2023
@sobolevn sobolevn self-assigned this Jul 17, 2023
sobolevn added a commit to sobolevn/cpython that referenced this issue Jul 17, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jul 17, 2023
…pythonGH-106832)

(cherry picked from commit ebf2c56)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jul 17, 2023
…pythonGH-106832)

(cherry picked from commit ebf2c56)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
@vstinner
Copy link
Member

vstinner commented Jul 17, 2023

I merged your fix, thanks. The backports will land automatically soon.

vstinner pushed a commit that referenced this issue Jul 17, 2023
GH-106832) (#106836)

gh-106831: Fix NULL check of d2i_SSL_SESSION() result in _ssl.c (GH-106832)
(cherry picked from commit ebf2c56)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
vstinner pushed a commit that referenced this issue Jul 17, 2023
GH-106832) (#106835)

gh-106831: Fix NULL check of d2i_SSL_SESSION() result in _ssl.c (GH-106832)
(cherry picked from commit ebf2c56)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-SSL type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants