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

Handle errors correctly in wait_helper in posixmodule.c #116404

Closed
sobolevn opened this issue Mar 6, 2024 · 0 comments
Closed

Handle errors correctly in wait_helper in posixmodule.c #116404

sobolevn opened this issue Mar 6, 2024 · 0 comments
Assignees
Labels
extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error

Comments

@sobolevn
Copy link
Member

sobolevn commented Mar 6, 2024

Bug report

There are several issues in this function:

  1. Our traditional case, when all errors are overwritten in a sequence preparation:

    cpython/Modules/posixmodule.c

    Lines 9584 to 9609 in d2f1b0e

    PyStructSequence_SET_ITEM(result, 0,
    PyFloat_FromDouble(doubletime(ru->ru_utime)));
    PyStructSequence_SET_ITEM(result, 1,
    PyFloat_FromDouble(doubletime(ru->ru_stime)));
    #define SET_INT(result, index, value)\
    PyStructSequence_SET_ITEM(result, index, PyLong_FromLong(value))
    SET_INT(result, 2, ru->ru_maxrss);
    SET_INT(result, 3, ru->ru_ixrss);
    SET_INT(result, 4, ru->ru_idrss);
    SET_INT(result, 5, ru->ru_isrss);
    SET_INT(result, 6, ru->ru_minflt);
    SET_INT(result, 7, ru->ru_majflt);
    SET_INT(result, 8, ru->ru_nswap);
    SET_INT(result, 9, ru->ru_inblock);
    SET_INT(result, 10, ru->ru_oublock);
    SET_INT(result, 11, ru->ru_msgsnd);
    SET_INT(result, 12, ru->ru_msgrcv);
    SET_INT(result, 13, ru->ru_nsignals);
    SET_INT(result, 14, ru->ru_nvcsw);
    SET_INT(result, 15, ru->ru_nivcsw);
    #undef SET_INT
    if (PyErr_Occurred()) {
    Py_DECREF(result);
    return NULL;
    }
  2. PyLong_FromPid can return NULL, but this case is ignored
    return Py_BuildValue("NiN", PyLong_FromPid(pid), status, result);

I have a PR ready.

Linked PRs

@sobolevn sobolevn added type-bug An unexpected behavior, bug, or error extension-modules C modules in the Modules dir labels Mar 6, 2024
@sobolevn sobolevn self-assigned this Mar 6, 2024
sobolevn added a commit to sobolevn/cpython that referenced this issue Mar 6, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Mar 6, 2024
…dule` (pythonGH-116405)

(cherry picked from commit 22ccf13)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Mar 6, 2024
…dule` (pythonGH-116405)

(cherry picked from commit 22ccf13)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
sobolevn added a commit that referenced this issue Mar 6, 2024
…odule` (GH-116405) (#116406)

gh-116404: Handle errors correctly in `wait_helper` in `posixmodule` (GH-116405)
(cherry picked from commit 22ccf13)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
sobolevn added a commit that referenced this issue Mar 6, 2024
…odule` (GH-116405) (#116407)

gh-116404: Handle errors correctly in `wait_helper` in `posixmodule` (GH-116405)
(cherry picked from commit 22ccf13)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
@sobolevn sobolevn closed this as completed Mar 6, 2024
adorilson pushed a commit to adorilson/cpython that referenced this issue Mar 25, 2024
diegorusso pushed a commit to diegorusso/cpython that referenced this issue Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant