Skip to content

Multiple things wrong with mkpwent in pwdmodule #116545

@sobolevn

Description

@sobolevn

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

Metadata

Metadata

Assignees

Labels

extension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions