summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2000-12-06 21:24:28 (GMT)
committerFred Drake <fdrake@acm.org>2000-12-06 21:24:28 (GMT)
commita30680b24035c972621c92394cb2b21cabbea6a5 (patch)
tree7985f89e658fe43689b4fad5ad77108aac24dfb4 /Modules
parent49312a52ece5819990e870ad75ed8422934fb2cc (diff)
downloadcpython-a30680b24035c972621c92394cb2b21cabbea6a5.zip
cpython-a30680b24035c972621c92394cb2b21cabbea6a5.tar.gz
cpython-a30680b24035c972621c92394cb2b21cabbea6a5.tar.bz2
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.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/posixmodule.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index a2251b1..2ddcebc 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -1904,12 +1904,21 @@ posix_getlogin(PyObject *self, PyObject *args)
PyObject *result = NULL;
if (PyArg_ParseTuple(args, ":getlogin")) {
- char *name = getlogin();
+ char *name;
+ int old_errno = errno;
- if (name == NULL)
- posix_error();
+ errno = 0;
+ name = getlogin();
+ if (name == NULL) {
+ if (errno)
+ posix_error();
+ else
+ PyErr_SetString(PyExc_OSError,
+ "unexpected NULL from getlogin()");
+ }
else
result = PyString_FromString(name);
+ errno = old_errno;
}
return result;
}