mirror of
https://github.com/python/cpython.git
synced 2025-10-21 14:12:27 +00:00
posix_getlogin(): Handle the possibility that getlogin() can return
NULL without setting errno; observed on Linux Mandrake 7.2 by an anonymous user. This closes bug #124758.
This commit is contained in:
parent
49312a52ec
commit
a30680b240
1 changed files with 12 additions and 3 deletions
|
@ -1904,12 +1904,21 @@ posix_getlogin(PyObject *self, PyObject *args)
|
||||||
PyObject *result = NULL;
|
PyObject *result = NULL;
|
||||||
|
|
||||||
if (PyArg_ParseTuple(args, ":getlogin")) {
|
if (PyArg_ParseTuple(args, ":getlogin")) {
|
||||||
char *name = getlogin();
|
char *name;
|
||||||
|
int old_errno = errno;
|
||||||
|
|
||||||
if (name == NULL)
|
errno = 0;
|
||||||
posix_error();
|
name = getlogin();
|
||||||
|
if (name == NULL) {
|
||||||
|
if (errno)
|
||||||
|
posix_error();
|
||||||
|
else
|
||||||
|
PyErr_SetString(PyExc_OSError,
|
||||||
|
"unexpected NULL from getlogin()");
|
||||||
|
}
|
||||||
else
|
else
|
||||||
result = PyString_FromString(name);
|
result = PyString_FromString(name);
|
||||||
|
errno = old_errno;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue