[SSSD] [PATCH] Do not change attr pointer with realloc

Jakub Hrozek jhrozek at redhat.com
Fri Apr 12 10:25:57 UTC 2013


https://fedorahosted.org/sssd/ticket/1799

One peculiarity of the sysdb_attrs_get_el interface is that if the
attribute does not exist, then the attrs array is reallocated and the
element is created. But in case other pointers are already pointing
into the array, the realloc might invalidate them.

One such case was in the sdap_process_ghost_members function where if
the group had no members, the "gh" pointer requested earlier might have
been invalidated by the realloc in order to create the member element

I'm actually pondering the idea of renaming the interface to make it
clear that if you request a nonexistent attr, the pointer already
pointing there might become invalid.
-------------- next part --------------
>From 15a04df406cdc7104c8b2e682052280c15fde594 Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek at redhat.com>
Date: Fri, 12 Apr 2013 12:01:01 +0200
Subject: [PATCH] Do not change attr pointer with realloc

https://fedorahosted.org/sssd/ticket/1799

One peculiarity of the sysdb_attrs_get_el interface is that if the
attribute does not exist, then the attrs array is reallocated and the
element is created. But in case other pointers are already pointing
into the array, the realloc might invalidate them.

One such case was in the sdap_process_ghost_members function where if
the group had no members, the "gh" pointer requested earlier might have
been invalidated by the realloc in order to create the member element.
---
 src/providers/ldap/sdap_async_groups.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/src/providers/ldap/sdap_async_groups.c b/src/providers/ldap/sdap_async_groups.c
index 9d4a84871793b3af9b6b57a06c358f91fcaf684d..c0584e80f49e49c9f2f119497446a8bb669afb3e 100644
--- a/src/providers/ldap/sdap_async_groups.c
+++ b/src/providers/ldap/sdap_async_groups.c
@@ -323,10 +323,22 @@ sdap_process_ghost_members(struct sysdb_attrs *attrs,
         return ret;
     }
 
-    ret = sysdb_attrs_get_el(attrs,
+    ret = sysdb_attrs_get_el_ext(attrs,
                              opts->group_map[SDAP_AT_GROUP_MEMBER].sys_name,
-                             &memberel);
-    if (ret != EOK) {
+                             false, &memberel);
+    if (ret == ENOENT) {
+        memberel = talloc_zero(attrs, struct ldb_message_element);
+        if (memberel == NULL) {
+            return ENOMEM;
+        }
+
+        memberel->name = talloc_strdup(memberel,
+                        opts->group_map[SDAP_AT_GROUP_MEMBER].sys_name);
+        if (memberel->name == NULL) {
+            talloc_free(memberel);
+            return ENOMEM;
+        }
+    } else if (ret != EOK) {
         DEBUG(SSSDBG_MINOR_FAILURE,
                 ("Error reading members: [%s]\n", strerror(ret)));
         return ret;
-- 
1.8.1.4



More information about the sssd-devel mailing list