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

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