s3:libads: Use a talloc_asprintf in ads_find_machine_acct()
authorAndreas Schneider <asn@samba.org>
Wed, 21 Aug 2019 10:22:32 +0000 (12:22 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Wed, 9 Oct 2019 07:06:35 +0000 (07:06 +0000)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Alexander Bokovoy <ab@samba.org>
source3/libads/ldap.c

index 5353ac5bf88271dc1e6c386a20cf5d1b6be70971..34b90a43c896ffac0d41391f2df6cf1dde7c55b3 100644 (file)
@@ -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;
 }