dpward / rpms / sssd

Forked from rpms/sssd 3 years ago
Clone

Blame SOURCES/0077-nss-use-enumeration-context-as-talloc-parent-for-cac.patch

71e593
From 406b731ddfbeb62623640cc37a7adc76af0a4b22 Mon Sep 17 00:00:00 2001
71e593
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
71e593
Date: Tue, 30 Oct 2018 13:21:28 +0100
71e593
Subject: [PATCH] nss: use enumeration context as talloc parent for cache req
71e593
 result
71e593
71e593
Otherwise we end up with memory leak since the result is never freed.
71e593
71e593
We need to convert nctx->*ent structures into talloc pointer so
71e593
we can use enum_ctx as parent.
71e593
71e593
Resolves:
71e593
https://pagure.io/SSSD/sssd/issue/3870
71e593
71e593
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
71e593
---
71e593
 src/responder/nss/nss_cmd.c     | 12 ++++++------
71e593
 src/responder/nss/nss_enum.c    |  2 +-
71e593
 src/responder/nss/nss_private.h |  6 +++---
71e593
 src/responder/nss/nsssrv.c      | 21 +++++++++++++++++++++
71e593
 4 files changed, 31 insertions(+), 10 deletions(-)
71e593
71e593
diff --git a/src/responder/nss/nss_cmd.c b/src/responder/nss/nss_cmd.c
71e593
index 9ee6ca805..25e663ed5 100644
71e593
--- a/src/responder/nss/nss_cmd.c
71e593
+++ b/src/responder/nss/nss_cmd.c
71e593
@@ -942,7 +942,7 @@ static errno_t nss_cmd_setpwent(struct cli_ctx *cli_ctx)
71e593
 
71e593
     nss_ctx = talloc_get_type(cli_ctx->rctx->pvt_ctx, struct nss_ctx);
71e593
 
71e593
-    return nss_setent(cli_ctx, CACHE_REQ_ENUM_USERS, &nss_ctx->pwent);
71e593
+    return nss_setent(cli_ctx, CACHE_REQ_ENUM_USERS, nss_ctx->pwent);
71e593
 }
71e593
 
71e593
 static errno_t nss_cmd_getpwent(struct cli_ctx *cli_ctx)
71e593
@@ -955,7 +955,7 @@ static errno_t nss_cmd_getpwent(struct cli_ctx *cli_ctx)
71e593
 
71e593
     return nss_getent(cli_ctx, CACHE_REQ_ENUM_USERS,
71e593
                       &state_ctx->pwent, nss_protocol_fill_pwent,
71e593
-                      &nss_ctx->pwent);
71e593
+                      nss_ctx->pwent);
71e593
 }
71e593
 
71e593
 static errno_t nss_cmd_endpwent(struct cli_ctx *cli_ctx)
71e593
@@ -998,7 +998,7 @@ static errno_t nss_cmd_setgrent(struct cli_ctx *cli_ctx)
71e593
 
71e593
     nss_ctx = talloc_get_type(cli_ctx->rctx->pvt_ctx, struct nss_ctx);
71e593
 
71e593
-    return nss_setent(cli_ctx, CACHE_REQ_ENUM_GROUPS, &nss_ctx->grent);
71e593
+    return nss_setent(cli_ctx, CACHE_REQ_ENUM_GROUPS, nss_ctx->grent);
71e593
 }
71e593
 
71e593
 static errno_t nss_cmd_getgrent(struct cli_ctx *cli_ctx)
71e593
@@ -1011,7 +1011,7 @@ static errno_t nss_cmd_getgrent(struct cli_ctx *cli_ctx)
71e593
 
71e593
     return nss_getent(cli_ctx, CACHE_REQ_ENUM_GROUPS,
71e593
                       &state_ctx->grent, nss_protocol_fill_grent,
71e593
-                      &nss_ctx->grent);
71e593
+                      nss_ctx->grent);
71e593
 }
71e593
 
71e593
 static errno_t nss_cmd_endgrent(struct cli_ctx *cli_ctx)
71e593
@@ -1093,7 +1093,7 @@ static errno_t nss_cmd_setservent(struct cli_ctx *cli_ctx)
71e593
 
71e593
     nss_ctx = talloc_get_type(cli_ctx->rctx->pvt_ctx, struct nss_ctx);
71e593
 
71e593
-    return nss_setent(cli_ctx, CACHE_REQ_ENUM_SVC, &nss_ctx->svcent);
71e593
+    return nss_setent(cli_ctx, CACHE_REQ_ENUM_SVC, nss_ctx->svcent);
71e593
 }
71e593
 
71e593
 static errno_t nss_cmd_getservent(struct cli_ctx *cli_ctx)
71e593
@@ -1106,7 +1106,7 @@ static errno_t nss_cmd_getservent(struct cli_ctx *cli_ctx)
71e593
 
71e593
     return nss_getent(cli_ctx, CACHE_REQ_ENUM_SVC,
71e593
                       &state_ctx->svcent, nss_protocol_fill_svcent,
71e593
-                      &nss_ctx->svcent);
71e593
+                      nss_ctx->svcent);
71e593
 }
71e593
 
71e593
 static errno_t nss_cmd_endservent(struct cli_ctx *cli_ctx)
71e593
diff --git a/src/responder/nss/nss_enum.c b/src/responder/nss/nss_enum.c
71e593
index a45b65233..9588943c9 100644
71e593
--- a/src/responder/nss/nss_enum.c
71e593
+++ b/src/responder/nss/nss_enum.c
71e593
@@ -138,7 +138,7 @@ static void nss_setent_internal_done(struct tevent_req *subreq)
71e593
     switch (ret) {
71e593
     case EOK:
71e593
         talloc_zfree(state->enum_ctx->result);
71e593
-        state->enum_ctx->result = talloc_steal(state->nss_ctx, result);
71e593
+        state->enum_ctx->result = talloc_steal(state->enum_ctx, result);
71e593
 
71e593
         if (state->type == CACHE_REQ_NETGROUP_BY_NAME) {
71e593
             /* We need to expand the netgroup into triples and members. */
71e593
diff --git a/src/responder/nss/nss_private.h b/src/responder/nss/nss_private.h
71e593
index aa8d8e9cd..cd0d35517 100644
71e593
--- a/src/responder/nss/nss_private.h
71e593
+++ b/src/responder/nss/nss_private.h
71e593
@@ -78,9 +78,9 @@ struct nss_ctx {
71e593
     const char **extra_attributes;
71e593
 
71e593
     /* Enumeration. */
71e593
-    struct nss_enum_ctx pwent;
71e593
-    struct nss_enum_ctx grent;
71e593
-    struct nss_enum_ctx svcent;
71e593
+    struct nss_enum_ctx *pwent;
71e593
+    struct nss_enum_ctx *grent;
71e593
+    struct nss_enum_ctx *svcent;
71e593
     hash_table_t *netgrent;
71e593
 
71e593
     /* Memory cache. */
71e593
diff --git a/src/responder/nss/nsssrv.c b/src/responder/nss/nsssrv.c
71e593
index 3c4edbb53..fb7326a02 100644
71e593
--- a/src/responder/nss/nsssrv.c
71e593
+++ b/src/responder/nss/nsssrv.c
71e593
@@ -345,6 +345,27 @@ int nss_process_init(TALLOC_CTX *mem_ctx,
71e593
         goto fail;
71e593
     }
71e593
 
71e593
+    nctx->pwent = talloc_zero(nctx, struct nss_enum_ctx);
71e593
+    if (nctx->pwent == NULL) {
71e593
+        DEBUG(SSSDBG_FATAL_FAILURE, "Unable to initialize pwent context!\n");
71e593
+        ret = ENOMEM;
71e593
+        goto fail;
71e593
+    }
71e593
+
71e593
+    nctx->grent = talloc_zero(nctx, struct nss_enum_ctx);
71e593
+    if (nctx->grent == NULL) {
71e593
+        DEBUG(SSSDBG_FATAL_FAILURE, "Unable to initialize grent context!\n");
71e593
+        ret = ENOMEM;
71e593
+        goto fail;
71e593
+    }
71e593
+
71e593
+    nctx->svcent = talloc_zero(nctx, struct nss_enum_ctx);
71e593
+    if (nctx->svcent == NULL) {
71e593
+        DEBUG(SSSDBG_FATAL_FAILURE, "Unable to initialize svcent context!\n");
71e593
+        ret = ENOMEM;
71e593
+        goto fail;
71e593
+    }
71e593
+
71e593
     nctx->netgrent = sss_ptr_hash_create(nctx, NULL, NULL);
71e593
     if (nctx->netgrent == NULL) {
71e593
         DEBUG(SSSDBG_FATAL_FAILURE, "Unable to initialize netgroups table!\n");
71e593
-- 
71e593
2.19.1
71e593