Skip to content

gh-83365: Fix incorrect return value in msvcrt_get_osfhandle_impl #21322

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

Closed

Conversation

gousaiyang
Copy link
Contributor

@gousaiyang gousaiyang commented Jul 4, 2020

As per #18580, msvcrt_get_osfhandle_impl should also return -1 instead of NULL when PySys_Audit fails.

https://bugs.python.org/issue39184

@gousaiyang
Copy link
Contributor Author

Hi @zooba, could you review this PR if you have time? This PR seems necessary to correct a mistake I made previously.

Copy link
Contributor

@nanjekyejoannah nanjekyejoannah left a comment

Choose a reason for hiding this comment

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

Dont we need any tests for this change?

@zooba
Copy link
Member

zooba commented Oct 10, 2022

If we had failure tests for all APIs with audit hooks, then I'd insist upon it. But we don't, and this only would've been caught by having broad testing (100+ new tests).

It's worth creating an issue for adding that set of tests. They ought to be fairly quick as well (though some will require e.g. making a real network connection, and most will require starting a new Python process for each API), but I think we can take this fix without adding all that.

@ghost
Copy link

ghost commented Oct 10, 2022

The following commit authors need to sign the Contributor License Agreement:

Click the button to sign:
CLA not signed

Copy link
Contributor

@kumaraditya303 kumaraditya303 left a comment

Choose a reason for hiding this comment

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

The CLA needs to be signed.

@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.

@AlexWaygood AlexWaygood changed the title bpo-39184: Fix incorrect return value in msvcrt_get_osfhandle_impl gh-83365: Fix incorrect return value in msvcrt_get_osfhandle_impl Dec 21, 2022
@@ -209,7 +209,7 @@ msvcrt_get_osfhandle_impl(PyObject *module, int fd)
/*[clinic end generated code: output=aca01dfe24637374 input=5fcfde9b17136aa2]*/
{
if (PySys_Audit("msvcrt.get_osfhandle", "(i)", fd) < 0) {
return NULL;
return -1;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return -1;
return (void*)-1;

@zooba
Copy link
Member

zooba commented Mar 6, 2023

Nothing heard from the OP, but also it doesn't seem to be necessary. This function call checks for any error, without looking at the return value.

@zooba zooba closed this Mar 6, 2023
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