]> arthur.barton.de Git - bup.git/commitdiff
grp_struct_to_py(): fix error handling
authorJohannes Berg <johannes@sipsolutions.net>
Fri, 19 Jun 2020 05:19:07 +0000 (07:19 +0200)
committerRob Browning <rlb@defaultvalue.org>
Sun, 5 Jul 2020 16:16:23 +0000 (11:16 -0500)
Both getgrgid_r() and getgrnam_r() *return* an error number
on failures, and don't store it to errno. Thus, rc will not
be less than zero, and we need to set errno before we can
create a python error from it.

Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Reviewed-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/_helpers.c

index b39db0ad9477e759cdd6d256505864b39e809753..67c39b568c66d5598dfbcc899188f34220e00a4e 100644 (file)
@@ -1829,11 +1829,10 @@ static PyObject *grp_struct_to_py(const struct group *grp, int rc)
     }
     if (rc == 0)
         return Py_BuildValue("O", Py_None);
+    errno = rc;
     if (rc == EIO || rc == EMFILE || rc == ENFILE)
         return PyErr_SetFromErrno(PyExc_IOError);
-    if (rc < 0)
-        return PyErr_SetFromErrno(PyExc_OSError);
-    assert (0);
+    return PyErr_SetFromErrno(PyExc_OSError);
 }
 
 static PyObject *bup_getgrgid(PyObject *self, PyObject *args)