Skip to content

bpo-42036:Fixed unchecked return in Modules/posixmodule.c #22696

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
wants to merge 4 commits into from

Conversation

monocle-ai
Copy link

@monocle-ai monocle-ai commented Oct 14, 2020

Instance 1
File : Modules/posixmodule.c
Enclosing Function : os_times_impl
Function : GetProcessTimes@20
https://github.com/siva-msft/cpython/blob/582aaf19e8b94a70c1f96792197770d604ba0fdf/Modules/posixmodule.c#L8505
Issue in: user, kernel

Code extract:

    FILETIME create, exit, kernel, user;
    HANDLE hProc;
    hProc = GetCurrentProcess();
    GetProcessTimes(hProc, &create, &exit, &kernel, &user); <------ HERE
    /* The fields of a FILETIME structure are the hi and lo part
       of a 64-bit value expressed in 100 nanosecond units.

How can I fix it?
Correct reference usage found in Modules/timemodule.c at line 1133.
https://github.com/siva-msft/cpython/blob/582aaf19e8b94a70c1f96792197770d604ba0fdf/Modules/timemodule.c#L1133
Code extract:

    BOOL ok;

    process = GetCurrentProcess();
    ok = GetProcessTimes(process, &creation_time, &exit_time, <------ HERE
                         &kernel_time, &user_time);
    if (!ok) {

Instance 2
File : Modules/posixmodule.c
Enclosing Function : posixmodule_exec
Function : dir_fd_converter
https://github.com/siva-msft/cpython/blob/582aaf19e8b94a70c1f96792197770d604ba0fdf/Modules/posixmodule.c#L15060
Issue in: ignored

Code extract:

    fd_specified("", -1);
    follow_symlinks_specified("", 1);
    dir_fd_and_follow_symlinks_invalid("chmod", DEFAULT_DIR_FD, 1);
    dir_fd_converter(Py_None, &ignored); <------ HERE
    dir_fd_unavailable(Py_None, &ignored);
    }

How can I fix it?
Correct reference usage found in Modules/posixmodule.c at line 1258.
https://github.com/siva-msft/cpython/blob/582aaf19e8b94a70c1f96792197770d604ba0fdf/Modules/posixmodule.c#L1258
Code extract:

dir_fd_unavailable(PyObject *o, void *p)
{
    int dir_fd;
    if (!dir_fd_converter(o, &dir_fd)) <------ HERE
        return 0;
    if (dir_fd != DEFAULT_DIR_FD) {

https://bugs.python.org/issue42036

**Instance 1**
File : `Modules/posixmodule.c` 
Enclosing Function : `os_times_impl`
Function : `GetProcessTimes@20` 
https://github.com/siva-msft/cpython/blob/582aaf19e8b94a70c1f96792197770d604ba0fdf/Modules/posixmodule.c#L8505
**Issue in**: _user, kernel_

**Code extract**:

```cpp
    FILETIME create, exit, kernel, user;
    HANDLE hProc;
    hProc = GetCurrentProcess();
    GetProcessTimes(hProc, &create, &exit, &kernel, &user); <------ HERE
    /* The fields of a FILETIME structure are the hi and lo part
       of a 64-bit value expressed in 100 nanosecond units.
```

**How can I fix it?** 
Correct reference usage found in `Modules/timemodule.c` at line `1133`.
https://github.com/siva-msft/cpython/blob/582aaf19e8b94a70c1f96792197770d604ba0fdf/Modules/timemodule.c#L1133
**Code extract**:

```cpp
    BOOL ok;

    process = GetCurrentProcess();
    ok = GetProcessTimes(process, &creation_time, &exit_time, <------ HERE
                         &kernel_time, &user_time);
    if (!ok) {
```


---
**Instance 2**
File : `Modules/posixmodule.c` 
Enclosing Function : `posixmodule_exec`
Function : `dir_fd_converter` 
https://github.com/siva-msft/cpython/blob/582aaf19e8b94a70c1f96792197770d604ba0fdf/Modules/posixmodule.c#L15060
**Issue in**: _ignored_

**Code extract**:

```cpp
    fd_specified("", -1);
    follow_symlinks_specified("", 1);
    dir_fd_and_follow_symlinks_invalid("chmod", DEFAULT_DIR_FD, 1);
    dir_fd_converter(Py_None, &ignored); <------ HERE
    dir_fd_unavailable(Py_None, &ignored);
    }
```

**How can I fix it?** 
Correct reference usage found in `Modules/posixmodule.c` at line `1258`.
https://github.com/siva-msft/cpython/blob/582aaf19e8b94a70c1f96792197770d604ba0fdf/Modules/posixmodule.c#L1258
**Code extract**:

```cpp
dir_fd_unavailable(PyObject *o, void *p)
{
    int dir_fd;
    if (!dir_fd_converter(o, &dir_fd)) <------ HERE
        return 0;
    if (dir_fd != DEFAULT_DIR_FD) {
```
@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

Recognized GitHub username

We couldn't find a bugs.python.org (b.p.o) account corresponding to the following GitHub usernames:

@monocle-ai

This might be simply due to a missing "GitHub Name" entry in one's b.p.o account settings. This is necessary for legal reasons before we can look at this contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Dec 17, 2020
@@ -15022,7 +15027,10 @@ posixmodule_exec(PyObject *m)
fd_specified("", -1);
follow_symlinks_specified("", 1);
dir_fd_and_follow_symlinks_invalid("chmod", DEFAULT_DIR_FD, 1);
dir_fd_converter(Py_None, &ignored);
if(!dir_fd_converter(Py_None, &ignored))
Copy link
Member

Choose a reason for hiding this comment

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

It never fails.

ok = GetProcessTimes(hProc, &create, &exit, &kernel, &user);
if (!ok) {
PyErr_SetFromWindowsErr(0);
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.

It is not even compiled.

Suggested change
return -1;
return NULL;

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

@github-actions github-actions bot removed the stale Stale PR or inactive for long period of time. label Feb 19, 2022
@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity. If the CLA is not signed within 14 days, it will be closed. See also https://devguide.python.org/pullrequest/#licensing

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Mar 21, 2022
@github-actions
Copy link

github-actions bot commented Apr 4, 2022

Closing this stale PR because the CLA is still not signed.

@github-actions github-actions bot closed this Apr 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting changes stale Stale PR or inactive for long period of time.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants