[SSSD] [PATCH] pysss: test return value of realloc.

Lukas Slebodnik lslebodn at redhat.com
Wed Aug 27 08:09:20 UTC 2014


ehlo,

warning reported by coverity

patch is attached

LS
-------------- next part --------------
>From a6c43a1d4ef1782ed7ac4b37b5fa39ca051de618 Mon Sep 17 00:00:00 2001
From: Lukas Slebodnik <lslebodn at redhat.com>
Date: Tue, 26 Aug 2014 12:59:53 +0200
Subject: [PATCH 2/2] pysss: test return value of realloc.

It is not very likely that realloc will return NULL, but it's better
to be defensive.

src/python/pysss.c:774: var_assigned: Assigning: "groups" = null return value from "realloc".
src/python/pysss.c:788: dereference: Dereferencing a null pointer "groups".
---
 src/python/pysss.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/python/pysss.c b/src/python/pysss.c
index 668d77c5694d5eeedd1ec97bb15ac242356be812..8f98f081c9600b74f5953faef40cb40b30388319 100644
--- a/src/python/pysss.c
+++ b/src/python/pysss.c
@@ -771,7 +771,11 @@ static PyObject *py_sss_getgrouplist(PyObject *self, PyObject *args)
     do {
         ret = getgrouplist(username, pw->pw_gid, groups, &ngroups);
         if (ret < ngroups) {
-            groups = realloc(groups, ngroups * sizeof(gid_t));
+            gid_t *tmp_groups = realloc(groups, ngroups * sizeof(gid_t));
+            if (tmp_groups == NULL) {
+                goto fail;
+            }
+            groups = tmp_groups;
         }
     } while (ret != ngroups);
 
-- 
2.1.0



More information about the sssd-devel mailing list