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