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

Skip to content

Multiple things wrong with mkpwent in pwdmodule #116545

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
sobolevn opened this issue Mar 9, 2024 · 0 comments
Closed

Multiple things wrong with mkpwent in pwdmodule #116545

sobolevn opened this issue Mar 9, 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 9, 2024

Bug report

Here's what's wrong:

  • PyObject *o = PyUnicode_DecodeFSDefault(val);
    PyStructSequence_SET_ITEM(v, i, o);
    }
    is not checked to be NULL, while it is possible
  • All errors here can overwrite each other:
    #define SETS(i,val) sets(v, i, val)
    SETS(setIndex++, p->pw_name);
    #if defined(HAVE_STRUCT_PASSWD_PW_PASSWD) && !defined(__ANDROID__)
    SETS(setIndex++, p->pw_passwd);
    #else
    SETS(setIndex++, "");
    #endif
    PyStructSequence_SET_ITEM(v, setIndex++, _PyLong_FromUid(p->pw_uid));
    PyStructSequence_SET_ITEM(v, setIndex++, _PyLong_FromGid(p->pw_gid));
    #if defined(HAVE_STRUCT_PASSWD_PW_GECOS)
    SETS(setIndex++, p->pw_gecos);
    #else
    SETS(setIndex++, "");
    #endif
    SETS(setIndex++, p->pw_dir);
    SETS(setIndex++, p->pw_shell);
  • XDECREF used, while v cannot be NULL:
    Py_XDECREF(v);

I will send a PR with the fix.

Linked PRs

@sobolevn sobolevn added type-bug An unexpected behavior, bug, or error extension-modules C modules in the Modules dir labels Mar 9, 2024
@sobolevn sobolevn self-assigned this Mar 9, 2024
sobolevn added a commit to sobolevn/cpython that referenced this issue Mar 9, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Mar 11, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Mar 11, 2024
sobolevn added a commit that referenced this issue Mar 11, 2024
…116548) (#116593)

gh-116545: Fix error handling in `mkpwent` in `pwdmodule` (GH-116548)
(cherry picked from commit ffd79be)

Co-authored-by: Nikita Sobolev <[email protected]>
sobolevn added a commit that referenced this issue Mar 11, 2024
…116548) (#116594)

gh-116545: Fix error handling in `mkpwent` in `pwdmodule` (GH-116548)
(cherry picked from commit ffd79be)

Co-authored-by: Nikita Sobolev <[email protected]>
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