URL: https://github.com/SSSD/sssd/pull/478 Author: sumit-bose Title: #478: ifp: use realloc in ifp_list_ctx_remaining_capacity() Action: opened
PR body: """ 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() will override results which are already in the list. This patch replaces it with talloc_realloc(). Resolves https://pagure.io/SSSD/sssd/issue/3608 """ To pull the PR as Git branch: git remote add ghsssd https://github.com/SSSD/sssd git fetch ghsssd pull/478/head:pr478 git checkout pr478
From 974806bf1f1d52272814b6407cc730093e4b5299 Mon Sep 17 00:00:00 2001 From: Sumit Bose <sb...@redhat.com> Date: Fri, 15 Dec 2017 12:09:06 +0100 Subject: [PATCH] ifp: use realloc in ifp_list_ctx_remaining_capacity() 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() will override results which are already in the list. This patch replaces it with talloc_realloc(). Resolves https://pagure.io/SSSD/sssd/issue/3608 --- 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 13455bbf7..b406e7f5b 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 1df646339..da4ab0679 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;
_______________________________________________ sssd-devel mailing list -- sssd-devel@lists.fedorahosted.org To unsubscribe send an email to sssd-devel-le...@lists.fedorahosted.org