summaryrefslogtreecommitdiff
path: root/src/python
diff options
context:
space:
mode:
authorAlexander Bokovoy <abokovoy@redhat.com>2013-07-22 16:03:39 +0300
committerJakub Hrozek <jhrozek@redhat.com>2013-07-23 14:24:35 +0200
commita41695473af0a932ffde0878211acef39f96edae (patch)
tree13530cf5f3454a8e93413f4afdb5e53ca5b67bd7 /src/python
parent90c5149110f5ee93716122b1621ea25667d3f13f (diff)
downloadsssd-a41695473af0a932ffde0878211acef39f96edae.tar.gz
sssd-a41695473af0a932ffde0878211acef39f96edae.tar.bz2
sssd-a41695473af0a932ffde0878211acef39f96edae.zip
pysss: prevent crashing when group is unresolvable
In unlikely case that an NSS module returns a reference to a group and we are unable to resolve it shortly after that, make sure these groups are skipped.
Diffstat (limited to 'src/python')
-rw-r--r--src/python/pysss.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/python/pysss.c b/src/python/pysss.c
index 6ae9a252..4dd03513 100644
--- a/src/python/pysss.c
+++ b/src/python/pysss.c
@@ -763,7 +763,7 @@ static PyObject *py_sss_getgrouplist(PyObject *self, PyObject *args)
struct group *gr;
int ngroups;
int ret;
- Py_ssize_t i;
+ Py_ssize_t i, idx;
PyObject *groups_tuple;
if(!PyArg_ParseTuple(args, discard_const_p(char, "s"), &username)) {
@@ -793,9 +793,20 @@ static PyObject *py_sss_getgrouplist(PyObject *self, PyObject *args)
goto fail;
}
+ /* Populate a tuple with names of groups
+ * In unlikely case of group not being able to resolve, skip it
+ * We also need to resize resulting tuple to avoid empty elements there */
+ idx = 0;
for (i = 0; i < ngroups; i++) {
gr = getgrgid(groups[i]);
- PyTuple_SetItem(groups_tuple, i, PyString_FromString(gr->gr_name));
+ if (gr) {
+ PyTuple_SetItem(groups_tuple, idx, PyString_FromString(gr->gr_name));
+ idx++;
+ }
+ }
+
+ if (i != idx) {
+ _PyTuple_Resize(&groups_tuple, idx);
}
return groups_tuple;