|
|
b2d430 |
From 83f4fbf2cb3f9318aedfa03e526671e3c444c40b Mon Sep 17 00:00:00 2001
|
|
|
b2d430 |
From: Sumit Bose <sbose@redhat.com>
|
|
|
b2d430 |
Date: Tue, 12 Jul 2016 13:16:43 +0200
|
|
|
b2d430 |
Subject: [PATCH 38/44] AD: avoid memory leak in netlogon_get_domain_info() and
|
|
|
b2d430 |
make it public
|
|
|
b2d430 |
|
|
|
b2d430 |
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
|
|
|
b2d430 |
---
|
|
|
b2d430 |
src/providers/ad/ad_common.h | 6 ++++++
|
|
|
b2d430 |
src/providers/ad/ad_domain_info.c | 29 ++++++++++++++++++++---------
|
|
|
b2d430 |
2 files changed, 26 insertions(+), 9 deletions(-)
|
|
|
b2d430 |
|
|
|
b2d430 |
diff --git a/src/providers/ad/ad_common.h b/src/providers/ad/ad_common.h
|
|
|
b2d430 |
index ce363c5a4122aa5e48ca83b0b2bdf63ff4372d91..f4a90e4f0a3fe5910071d5fe690d0a356e2a0bd1 100644
|
|
|
b2d430 |
--- a/src/providers/ad/ad_common.h
|
|
|
b2d430 |
+++ b/src/providers/ad/ad_common.h
|
|
|
b2d430 |
@@ -185,4 +185,10 @@ errno_t ad_autofs_init(TALLOC_CTX *mem_ctx,
|
|
|
b2d430 |
errno_t ad_machine_account_password_renewal_init(struct be_ctx *be_ctx,
|
|
|
b2d430 |
struct ad_options *ad_opts);
|
|
|
b2d430 |
|
|
|
b2d430 |
+errno_t netlogon_get_domain_info(TALLOC_CTX *mem_ctx,
|
|
|
b2d430 |
+ struct sysdb_attrs *reply,
|
|
|
b2d430 |
+ char **_flat_name,
|
|
|
b2d430 |
+ char **_site,
|
|
|
b2d430 |
+ char **_forest);
|
|
|
b2d430 |
+
|
|
|
b2d430 |
#endif /* AD_COMMON_H_ */
|
|
|
b2d430 |
diff --git a/src/providers/ad/ad_domain_info.c b/src/providers/ad/ad_domain_info.c
|
|
|
b2d430 |
index 5f17ae5427b1206af3ad03dccce9452aefc2e6e2..a06379c263878aa95741055636d0a12764f3ad8c 100644
|
|
|
b2d430 |
--- a/src/providers/ad/ad_domain_info.c
|
|
|
b2d430 |
+++ b/src/providers/ad/ad_domain_info.c
|
|
|
b2d430 |
@@ -35,12 +35,11 @@
|
|
|
b2d430 |
#include "providers/ad/ad_common.h"
|
|
|
b2d430 |
#include "util/util.h"
|
|
|
b2d430 |
|
|
|
b2d430 |
-static errno_t
|
|
|
b2d430 |
-netlogon_get_domain_info(TALLOC_CTX *mem_ctx,
|
|
|
b2d430 |
- struct sysdb_attrs *reply,
|
|
|
b2d430 |
- char **_flat_name,
|
|
|
b2d430 |
- char **_site,
|
|
|
b2d430 |
- char **_forest)
|
|
|
b2d430 |
+errno_t netlogon_get_domain_info(TALLOC_CTX *mem_ctx,
|
|
|
b2d430 |
+ struct sysdb_attrs *reply,
|
|
|
b2d430 |
+ char **_flat_name,
|
|
|
b2d430 |
+ char **_site,
|
|
|
b2d430 |
+ char **_forest)
|
|
|
b2d430 |
{
|
|
|
b2d430 |
errno_t ret;
|
|
|
b2d430 |
struct ldb_message_element *el;
|
|
|
b2d430 |
@@ -51,6 +50,7 @@ netlogon_get_domain_info(TALLOC_CTX *mem_ctx,
|
|
|
b2d430 |
const char *flat_name;
|
|
|
b2d430 |
const char *site;
|
|
|
b2d430 |
const char *forest;
|
|
|
b2d430 |
+ TALLOC_CTX *tmp_ctx;
|
|
|
b2d430 |
|
|
|
b2d430 |
ret = sysdb_attrs_get_el(reply, AD_AT_NETLOGON, &el);
|
|
|
b2d430 |
if (ret != EOK) {
|
|
|
b2d430 |
@@ -66,13 +66,24 @@ netlogon_get_domain_info(TALLOC_CTX *mem_ctx,
|
|
|
b2d430 |
return EIO;
|
|
|
b2d430 |
}
|
|
|
b2d430 |
|
|
|
b2d430 |
+ tmp_ctx = talloc_new(NULL);
|
|
|
b2d430 |
+ if (tmp_ctx == NULL) {
|
|
|
b2d430 |
+ DEBUG(SSSDBG_OP_FAILURE, "talloc_new failed.\n");
|
|
|
b2d430 |
+ return ENOMEM;
|
|
|
b2d430 |
+ }
|
|
|
b2d430 |
+
|
|
|
b2d430 |
blob.data = el->values[0].data;
|
|
|
b2d430 |
blob.length = el->values[0].length;
|
|
|
b2d430 |
|
|
|
b2d430 |
- ndr_pull = ndr_pull_init_blob(&blob, mem_ctx);
|
|
|
b2d430 |
+ /* The ndr_pull_* calls do not use ndr_pull as a talloc context to
|
|
|
b2d430 |
+ * allocate memory but the second argument of ndr_pull_init_blob(). To
|
|
|
b2d430 |
+ * make sure no memory is leaked here a temporary talloc context is
|
|
|
b2d430 |
+ * needed. */
|
|
|
b2d430 |
+ ndr_pull = ndr_pull_init_blob(&blob, tmp_ctx);
|
|
|
b2d430 |
if (ndr_pull == NULL) {
|
|
|
b2d430 |
DEBUG(SSSDBG_OP_FAILURE, "ndr_pull_init_blob() failed.\n");
|
|
|
b2d430 |
- return ENOMEM;
|
|
|
b2d430 |
+ ret = ENOMEM;
|
|
|
b2d430 |
+ goto done;
|
|
|
b2d430 |
}
|
|
|
b2d430 |
|
|
|
b2d430 |
ndr_err = ndr_pull_netlogon_samlogon_response(ndr_pull, NDR_SCALARS,
|
|
|
b2d430 |
@@ -146,7 +157,7 @@ netlogon_get_domain_info(TALLOC_CTX *mem_ctx,
|
|
|
b2d430 |
|
|
|
b2d430 |
ret = EOK;
|
|
|
b2d430 |
done:
|
|
|
b2d430 |
- talloc_free(ndr_pull);
|
|
|
b2d430 |
+ talloc_free(tmp_ctx);
|
|
|
b2d430 |
return ret;
|
|
|
b2d430 |
}
|
|
|
b2d430 |
|
|
|
b2d430 |
--
|
|
|
b2d430 |
2.4.11
|
|
|
b2d430 |
|