On Tue, Feb 14, 2012 at 02:54:21PM +0100, Jakub Hrozek wrote:
> On Tue, Feb 14, 2012 at 08:45:59AM -0500, Stephen Gallagher wrote:
> > On Tue, 2012-02-14 at 14:34 +0100, Jakub Hrozek wrote:
> > > https://fedorahosted.org/sssd/ticket/1186
> > 
> > Obvious ack. Great catch!
> 
> We might want to fix the other places where parentage is kept to state
> even for array members -- having the parentage link to the array is more
> talloc-y.
> 
> Another patch is attached.

Yet another patch that also fixes users and services.
From e00c764cc00b55f9ba757e2d84d32107dc71d461 Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <[email protected]>
Date: Tue, 14 Feb 2012 12:30:55 +0100
Subject: [PATCH] Fix memory hierarchy when processing nested group
 memberships

https://fedorahosted.org/sssd/ticket/1186
---
 src/providers/ldap/sdap_async_groups.c     |    4 ++--
 src/providers/ldap/sdap_async_initgroups.c |   14 ++++++++------
 src/providers/ldap/sdap_async_services.c   |    4 ++--
 src/providers/ldap/sdap_async_users.c      |    3 ++-
 4 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/src/providers/ldap/sdap_async_groups.c 
b/src/providers/ldap/sdap_async_groups.c
index 
feb13db98bceb11098d3827e674dba8f94258f76..061a99c8e49757ceeaaee67e5537ddb930012e7a
 100644
--- a/src/providers/ldap/sdap_async_groups.c
+++ b/src/providers/ldap/sdap_async_groups.c
@@ -1323,10 +1323,10 @@ static void sdap_get_groups_process(struct tevent_req 
*subreq)
         }
 
         /* Copy the new groups into the list
-         * They're already allocated on 'state'
          */
         for (i = 0; i < count; i++) {
-            state->groups[state->count + i] = groups[i];
+            state->groups[state->count + i] =
+                talloc_steal(state->groups, groups[i]);
         }
 
         state->count += count;
diff --git a/src/providers/ldap/sdap_async_initgroups.c 
b/src/providers/ldap/sdap_async_initgroups.c
index 
964f5b0a0f36951a7bf863b8e1f565e3e77407cf..5e0e184ad3d8435dbf7507edbd58d2568c421d39
 100644
--- a/src/providers/ldap/sdap_async_initgroups.c
+++ b/src/providers/ldap/sdap_async_initgroups.c
@@ -426,10 +426,10 @@ static void sdap_initgr_rfc2307_process(struct tevent_req 
*subreq)
         }
 
         /* Copy the new groups into the list.
-         * They're already allocated on 'state'.
          */
         for (i = 0; i < count; i++) {
-            state->ldap_groups[state->ldap_groups_count + i] = ldap_groups[i];
+            state->ldap_groups[state->ldap_groups_count + i] =
+                talloc_steal(state->ldap_groups, ldap_groups[i]);
         }
 
         state->ldap_groups_count += count;
@@ -1553,11 +1553,10 @@ static void sdap_initgr_rfc2307bis_process(struct 
tevent_req *subreq)
         }
 
         /* Copy the new groups into the list.
-         * They're already allocated on 'state'.
          */
         for (i = 0; i < count; i++) {
             state->direct_groups[state->num_direct_parents + i] =
-                    ldap_groups[i];
+                    talloc_steal(state->direct_groups, ldap_groups[i]);
         }
 
         state->num_direct_parents += count;
@@ -2204,10 +2203,13 @@ static void rfc2307bis_nested_groups_process(struct 
tevent_req *subreq)
         }
 
         /* Copy the new groups into the list.
-         * They're already allocated on 'state'.
+         * They're allocated on 'state' so we need to move them
+         * onto ldap_parents so that the data won't disappear when
+         * we finish this nesting level.
          */
         for (i = 0; i < count; i++) {
-            state->ldap_parents[state->parents_count + i] = ldap_groups[i];
+            state->ldap_parents[state->parents_count + i] =
+                talloc_steal(state->ldap_parents, ldap_groups[i]);
         }
 
         state->parents_count += count;
diff --git a/src/providers/ldap/sdap_async_services.c 
b/src/providers/ldap/sdap_async_services.c
index 
b472e4072eadee454616ba42bfca8f2b15dd059b..5bc044630f1bdeded945d1878f02aa2acc55c3dd
 100644
--- a/src/providers/ldap/sdap_async_services.c
+++ b/src/providers/ldap/sdap_async_services.c
@@ -199,10 +199,10 @@ sdap_get_services_process(struct tevent_req *subreq)
         }
 
         /* Copy the new services into the list
-         * They're already allocated on 'state'
          */
         for (i = 0; i < count; i++) {
-            state->services[state->count + i] = services[i];
+            state->services[state->count + i] =
+                talloc_steal(state->services, services[i]);
         }
 
         state->count += count;
diff --git a/src/providers/ldap/sdap_async_users.c 
b/src/providers/ldap/sdap_async_users.c
index 
fa9c0a799d363a32f95c1a6ef5ef94afe3033b83..a8595ac8919c673df99aa91bf606bb3287cd97e2
 100644
--- a/src/providers/ldap/sdap_async_users.c
+++ b/src/providers/ldap/sdap_async_users.c
@@ -528,7 +528,8 @@ static void sdap_get_users_process(struct tevent_req 
*subreq)
          * They're already allocated on 'state'
          */
         for (i = 0; i < count; i++) {
-            state->users[state->count + i] = users[i];
+            state->users[state->count + i] =
+                talloc_steal(state->users, users[i]);
         }
 
         state->count += count;
-- 
1.7.7.6

_______________________________________________
sssd-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/sssd-devel

Reply via email to