Blame SOURCES/0090-ifp-use-realloc-in-ifp_list_ctx_remaining_capacity.patch

9f2ebf
From 674c5c3ba930a8546371ea8e138ff20a15090431 Mon Sep 17 00:00:00 2001
9f2ebf
From: Sumit Bose <sbose@redhat.com>
9f2ebf
Date: Fri, 15 Dec 2017 12:09:06 +0100
9f2ebf
Subject: [PATCH 90/90] ifp: use realloc in ifp_list_ctx_remaining_capacity()
9f2ebf
MIME-Version: 1.0
9f2ebf
Content-Type: text/plain; charset=UTF-8
9f2ebf
Content-Transfer-Encoding: 8bit
9f2ebf
9f2ebf
ifp_list_ctx_remaining_capacity() might be called multiple times if
9f2ebf
results from multiple domains are added to the result list.
9f2ebf
9f2ebf
The current use of talloc_zero_array() which was introduced with commit
9f2ebf
b0b9222 will override results which are already in the list. This causes
9f2ebf
a regression since it worked before.
9f2ebf
9f2ebf
This patch replaces it with talloc_realloc().
9f2ebf
9f2ebf
Resolves https://pagure.io/SSSD/sssd/issue/3608
9f2ebf
9f2ebf
Reviewed-by: Fabiano FidĂȘncio <fidencio@redhat.com>
9f2ebf
(cherry picked from commit 510ac193900a7bb9dfae10c0ca4607c224b265af)
9f2ebf
---
9f2ebf
 src/responder/ifp/ifp_private.h |  1 +
9f2ebf
 src/responder/ifp/ifpsrv_util.c | 16 ++++++++++++----
9f2ebf
 2 files changed, 13 insertions(+), 4 deletions(-)
9f2ebf
9f2ebf
diff --git a/src/responder/ifp/ifp_private.h b/src/responder/ifp/ifp_private.h
9f2ebf
index 13455bbf70860fb6dbfa3bb65fe3bd565d53257d..b406e7f5bab3e0dbc9696a5ab58e46b6ee7839eb 100644
9f2ebf
--- a/src/responder/ifp/ifp_private.h
9f2ebf
+++ b/src/responder/ifp/ifp_private.h
9f2ebf
@@ -93,6 +93,7 @@ struct ifp_list_ctx {
9f2ebf
     struct ifp_ctx *ctx;
9f2ebf
 
9f2ebf
     const char **paths;
9f2ebf
+    size_t paths_max;
9f2ebf
     size_t path_count;
9f2ebf
 };
9f2ebf
 
9f2ebf
diff --git a/src/responder/ifp/ifpsrv_util.c b/src/responder/ifp/ifpsrv_util.c
9f2ebf
index 1df646339526186e862dcd09cddd971b77c20a8b..da4ab06796a99c930b7a4ad21ca408814f8b4c49 100644
9f2ebf
--- a/src/responder/ifp/ifpsrv_util.c
9f2ebf
+++ b/src/responder/ifp/ifpsrv_util.c
9f2ebf
@@ -372,7 +372,9 @@ struct ifp_list_ctx *ifp_list_ctx_new(struct sbus_request *sbus_req,
9f2ebf
     list_ctx->ctx = ctx;
9f2ebf
     list_ctx->dom = ctx->rctx->domains;
9f2ebf
     list_ctx->filter = filter;
9f2ebf
-    list_ctx->paths = talloc_zero_array(list_ctx, const char *, 1);
9f2ebf
+    list_ctx->paths_max = 1;
9f2ebf
+    list_ctx->paths = talloc_zero_array(list_ctx, const char *,
9f2ebf
+                                        list_ctx->paths_max);
9f2ebf
     if (list_ctx->paths == NULL) {
9f2ebf
         talloc_free(list_ctx);
9f2ebf
         return NULL;
9f2ebf
@@ -387,6 +389,7 @@ errno_t ifp_list_ctx_remaining_capacity(struct ifp_list_ctx *list_ctx,
9f2ebf
 {
9f2ebf
     size_t capacity = list_ctx->limit - list_ctx->path_count;
9f2ebf
     errno_t ret;
9f2ebf
+    size_t c;
9f2ebf
 
9f2ebf
     if (list_ctx->limit == 0) {
9f2ebf
         capacity = entries;
9f2ebf
@@ -396,19 +399,24 @@ errno_t ifp_list_ctx_remaining_capacity(struct ifp_list_ctx *list_ctx,
9f2ebf
     if (capacity < entries) {
9f2ebf
         DEBUG(SSSDBG_MINOR_FAILURE,
9f2ebf
               "IFP list request has limit of %"PRIu32" entries but back end "
9f2ebf
-              "returned %zu entries\n", list_ctx->limit, entries);
9f2ebf
+              "returned %zu entries\n", list_ctx->limit,
9f2ebf
+                                        list_ctx->path_count + entries);
9f2ebf
     } else {
9f2ebf
         capacity = entries;
9f2ebf
     }
9f2ebf
 
9f2ebf
 immediately:
9f2ebf
-    talloc_zfree(list_ctx->paths);
9f2ebf
-    list_ctx->paths = talloc_zero_array(list_ctx, const char *, capacity);
9f2ebf
+    list_ctx->paths_max = list_ctx->path_count + capacity;
9f2ebf
+    list_ctx->paths = talloc_realloc(list_ctx, list_ctx->paths, const char *,
9f2ebf
+                                     list_ctx->paths_max);
9f2ebf
     if (list_ctx->paths == NULL) {
9f2ebf
         DEBUG(SSSDBG_CRIT_FAILURE, "talloc_zero_array() failed\n");
9f2ebf
         ret = ENOMEM;
9f2ebf
         goto done;
9f2ebf
     }
9f2ebf
+    for (c = list_ctx->path_count; c < list_ctx->paths_max; c++) {
9f2ebf
+        list_ctx->paths[c] = NULL;
9f2ebf
+    }
9f2ebf
 
9f2ebf
     *_capacity = capacity;
9f2ebf
     ret = EOK;
9f2ebf
-- 
9f2ebf
2.14.3
9f2ebf