From c1aa2a7370e2265ce4ffa2636fa9f6a43577f439 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20=C4=8Cech?= <pcech@redhat.com>
Date: Tue, 28 Mar 2017 12:07:55 +0200
Subject: [PATCH] IFP: Fix of limit = 0 (unlimited result)

If we set limit to 0 it means that result is unlimited. Internally we
restrict number of result by allocation of result array.
In unlimited case there was a bug and zero array was allocated.
This fix allocates neccessary array when we know real result size.

Resolves:
https://pagure.io/SSSD/sssd/issue/3306
---
 src/responder/ifp/ifpsrv_util.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/src/responder/ifp/ifpsrv_util.c b/src/responder/ifp/ifpsrv_util.c
index 5866d30..c948d5a 100644
--- a/src/responder/ifp/ifpsrv_util.c
+++ b/src/responder/ifp/ifpsrv_util.c
@@ -314,6 +314,15 @@ size_t ifp_list_ctx_remaining_capacity(struct ifp_list_ctx *list_ctx,
 {
     size_t capacity = list_ctx->limit - list_ctx->path_count;
 
+    if (list_ctx->limit == 0) {
+        list_ctx->paths = talloc_zero_array(list_ctx, const char *, entries);
+        if (list_ctx->paths == NULL) {
+            DEBUG(SSSDBG_CRIT_FAILURE, "talloc_zero_array() failed\n");
+            return 0;
+        }
+        return entries;
+    }
+
     if (capacity < entries) {
         DEBUG(SSSDBG_MINOR_FAILURE,
               "IFP list request has limit of %"PRIu32" entries but back end "
