]> granicus.if.org Git - python/commitdiff
posix_getlogin(): Handle the possibility that getlogin() can return
authorFred Drake <fdrake@acm.org>
Wed, 6 Dec 2000 21:24:28 +0000 (21:24 +0000)
committerFred Drake <fdrake@acm.org>
Wed, 6 Dec 2000 21:24:28 +0000 (21:24 +0000)
                   NULL without setting errno; observed on Linux
                   Mandrake 7.2 by an anonymous user.

This closes bug #124758.

Modules/posixmodule.c

index a2251b1df8fde728175b66de7c03bdbdc3e61f6c..2ddcebc855ef9c4494e93b4781ab0a55d77184dd 100644 (file)
@@ -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;
 }