Blob Blame History Raw
From 25193cfe110b328b428cde9641400f7dc999416e Mon Sep 17 00:00:00 2001
From: Pavel Reichl <preichl@redhat.com>
Date: Fri, 25 Apr 2014 14:42:39 +0100
Subject: [PATCH 124/124] AD Provider: bugfix use-after-free

Resolves:
https://fedorahosted.org/sssd/ticket/2322

Reviewed-by: Sumit Bose <sbose@redhat.com>
(cherry picked from commit ed61bfc5184d9c7a46d17681a22a1abb64423708)
---
 src/providers/data_provider_be.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/providers/data_provider_be.c b/src/providers/data_provider_be.c
index 37b687f25810447c08c6e0c6e8da4f64c99a5f5f..f85c63065252b24d4eeec0d2671ab0a1a16d4b9a 100644
--- a/src/providers/data_provider_be.c
+++ b/src/providers/data_provider_be.c
@@ -210,7 +210,8 @@ void be_req_terminate(struct be_req *be_req,
 void be_terminate_domain_requests(struct be_ctx *be_ctx,
                                   const char *domain)
 {
-    struct be_req *be_req = NULL;
+    struct be_req *be_req;
+    struct be_req *next_be_req;
 
     DEBUG(SSSDBG_TRACE_FUNC, ("Terminating requests for domain [%s]\n",
                               domain));
@@ -220,11 +221,15 @@ void be_terminate_domain_requests(struct be_ctx *be_ctx,
         return;
     }
 
-    DLIST_FOR_EACH(be_req, be_ctx->active_requests) {
+    be_req = be_ctx->active_requests;
+    while (be_req) {
+        /* save pointer to next request in case be_req will be freed */
+        next_be_req = be_req->next;
         if (strcmp(domain, be_req->domain->name) == 0) {
             be_req_terminate(be_req, DP_ERR_FATAL, ERR_DOMAIN_NOT_FOUND,
                              sss_strerror(ERR_DOMAIN_NOT_FOUND));
         }
+        be_req = next_be_req;
     }
 }
 
-- 
1.9.0