From 35f3e4aed1f1c2ba1c8dc50921f238937f343357 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Wed, 21 Aug 2019 12:22:32 +0200 Subject: [PATCH] s3:libads: Use a talloc_asprintf in ads_find_machine_acct() Signed-off-by: Andreas Schneider Reviewed-by: Alexander Bokovoy --- source3/libads/ldap.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/source3/libads/ldap.c b/source3/libads/ldap.c index 5353ac5bf88..34b90a43c89 100644 --- a/source3/libads/ldap.c +++ b/source3/libads/ldap.c @@ -1367,18 +1367,22 @@ char *ads_parent_dn(const char *dn) ADS_STATUS status; char *expr; const char *attrs[] = {"*", "msDS-SupportedEncryptionTypes", "nTSecurityDescriptor", NULL}; + TALLOC_CTX *frame = talloc_stackframe(); *res = NULL; /* the easiest way to find a machine account anywhere in the tree is to look for hostname$ */ - if (asprintf(&expr, "(samAccountName=%s$)", machine) == -1) { - DEBUG(1, ("asprintf failed!\n")); - return ADS_ERROR_NT(NT_STATUS_NO_MEMORY); + expr = talloc_asprintf(frame, "(samAccountName=%s$)", machine); + if (expr == NULL) { + status = ADS_ERROR_NT(NT_STATUS_NO_MEMORY); + goto done; } status = ads_search(ads, res, expr, attrs); - SAFE_FREE(expr); + +done: + TALLOC_FREE(frame); return status; } -- 2.47.3