Blame SOURCES/0035-simple-fix-memory-leak-while-reloading-lists.patch

bac598
From 19c2c641e669ee1c08d6706c132625dc30e64609 Mon Sep 17 00:00:00 2001
bac598
From: Sumit Bose <sbose@redhat.com>
bac598
Date: Tue, 12 Jan 2021 16:40:56 +0100
bac598
Subject: [PATCH] simple: fix memory leak while reloading lists
bac598
bac598
The simple access provider will reload the access and deny lists at
bac598
runtime to make sure that users and groups from domains which are
bac598
discovered at runtime are properly processed.
bac598
bac598
While reloading the lists the original lists are not freed and an
bac598
intermediate list wasn't removed as well.
bac598
bac598
Resolves: https://github.com/SSSD/sssd/issues/5456
bac598
bac598
:fixes: Memory leak in the simple access provider
bac598
bac598
Reviewed-by: Alexey Tikhonov <atikhono@redhat.com>
bac598
---
bac598
 src/providers/simple/simple_access.c | 28 +++++++++++++++++++++-------
bac598
 1 file changed, 21 insertions(+), 7 deletions(-)
bac598
bac598
diff --git a/src/providers/simple/simple_access.c b/src/providers/simple/simple_access.c
bac598
index 1868569b1..49226adf2 100644
bac598
--- a/src/providers/simple/simple_access.c
bac598
+++ b/src/providers/simple/simple_access.c
bac598
@@ -117,17 +117,13 @@ int simple_access_obtain_filter_lists(struct simple_ctx *ctx)
bac598
         const char *name;
bac598
         const char *option;
bac598
         char **orig_list;
bac598
-        char ***ctx_list;
bac598
+        char **ctx_list;
bac598
     } lists[] = {{"Allow users", CONFDB_SIMPLE_ALLOW_USERS, NULL, NULL},
bac598
                  {"Deny users", CONFDB_SIMPLE_DENY_USERS, NULL, NULL},
bac598
                  {"Allow groups", CONFDB_SIMPLE_ALLOW_GROUPS, NULL, NULL},
bac598
                  {"Deny groups", CONFDB_SIMPLE_DENY_GROUPS, NULL, NULL},
bac598
                  {NULL, NULL, NULL, NULL}};
bac598
 
bac598
-    lists[0].ctx_list = &ctx->allow_users;
bac598
-    lists[1].ctx_list = &ctx->deny_users;
bac598
-    lists[2].ctx_list = &ctx->allow_groups;
bac598
-    lists[3].ctx_list = &ctx->deny_groups;
bac598
 
bac598
     ret = sysdb_master_domain_update(bectx->domain);
bac598
     if (ret != EOK) {
bac598
@@ -141,7 +137,6 @@ int simple_access_obtain_filter_lists(struct simple_ctx *ctx)
bac598
                                         lists[i].option, &lists[i].orig_list);
bac598
         if (ret == ENOENT) {
bac598
             DEBUG(SSSDBG_FUNC_DATA, "%s list is empty.\n", lists[i].name);
bac598
-            *lists[i].ctx_list = NULL;
bac598
             continue;
bac598
         } else if (ret != EOK) {
bac598
             DEBUG(SSSDBG_CRIT_FAILURE, "confdb_get_string_as_list failed.\n");
bac598
@@ -149,7 +144,8 @@ int simple_access_obtain_filter_lists(struct simple_ctx *ctx)
bac598
         }
bac598
 
bac598
         ret = simple_access_parse_names(ctx, bectx, lists[i].orig_list,
bac598
-                                        lists[i].ctx_list);
bac598
+                                        &lists[i].ctx_list);
bac598
+        talloc_free(lists[i].orig_list);
bac598
         if (ret != EOK) {
bac598
             DEBUG(SSSDBG_CRIT_FAILURE, "Unable to parse %s list [%d]: %s\n",
bac598
                                         lists[i].name, ret, sss_strerror(ret));
bac598
@@ -157,6 +153,18 @@ int simple_access_obtain_filter_lists(struct simple_ctx *ctx)
bac598
         }
bac598
     }
bac598
 
bac598
+    talloc_free(ctx->allow_users);
bac598
+    ctx->allow_users = talloc_steal(ctx, lists[0].ctx_list);
bac598
+
bac598
+    talloc_free(ctx->deny_users);
bac598
+    ctx->deny_users = talloc_steal(ctx, lists[1].ctx_list);
bac598
+
bac598
+    talloc_free(ctx->allow_groups);
bac598
+    ctx->allow_groups = talloc_steal(ctx, lists[2].ctx_list);
bac598
+
bac598
+    talloc_free(ctx->deny_groups);
bac598
+    ctx->deny_groups = talloc_steal(ctx, lists[3].ctx_list);
bac598
+
bac598
     if (!ctx->allow_users &&
bac598
             !ctx->allow_groups &&
bac598
             !ctx->deny_users &&
bac598
@@ -165,9 +173,15 @@ int simple_access_obtain_filter_lists(struct simple_ctx *ctx)
bac598
               "No rules supplied for simple access provider. "
bac598
                "Access will be granted for all users.\n");
bac598
     }
bac598
+
bac598
+
bac598
     return EOK;
bac598
 
bac598
 failed:
bac598
+    for (i = 0; lists[i].name != NULL; i++) {
bac598
+        talloc_free(lists[i].ctx_list);
bac598
+    }
bac598
+
bac598
     return ret;
bac598
 }
bac598
 
bac598
-- 
bac598
2.21.3
bac598