b6b438
From cb51fd8abb0f0d3fa672452cd15d49af193de6ee Mon Sep 17 00:00:00 2001
b6b438
From: Andreas Schneider <asn@samba.org>
b6b438
Date: Tue, 16 Jul 2019 16:02:12 +0200
b6b438
Subject: [PATCH 062/187] s3:rpc_server: Use a stackframe for temporary memory
b6b438
b6b438
Signed-off-by: Andreas Schneider <asn@samba.org>
b6b438
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
b6b438
(cherry picked from commit 1c84bda361678cb6c4685cff17a2d5a5026f2bce)
b6b438
---
b6b438
 source3/rpc_server/netlogon/srv_netlog_nt.c | 20 +++++++++++++-------
b6b438
 1 file changed, 13 insertions(+), 7 deletions(-)
b6b438
b6b438
diff --git a/source3/rpc_server/netlogon/srv_netlog_nt.c b/source3/rpc_server/netlogon/srv_netlog_nt.c
b6b438
index d5267bf7062..791aa7acaff 100644
b6b438
--- a/source3/rpc_server/netlogon/srv_netlog_nt.c
b6b438
+++ b/source3/rpc_server/netlogon/srv_netlog_nt.c
b6b438
@@ -1134,6 +1134,7 @@ static NTSTATUS netr_set_machine_account_password(TALLOC_CTX *mem_ctx,
b6b438
 	int rc;
b6b438
 	DATA_BLOB session_key;
b6b438
 	enum samr_UserInfoLevel infolevel;
b6b438
+	TALLOC_CTX *frame = talloc_stackframe();
b6b438
 
b6b438
 	ZERO_STRUCT(user_handle);
b6b438
 
b6b438
@@ -1144,7 +1145,7 @@ static NTSTATUS netr_set_machine_account_password(TALLOC_CTX *mem_ctx,
b6b438
 		goto out;
b6b438
 	}
b6b438
 
b6b438
-	rc = tsocket_address_inet_from_strings(mem_ctx,
b6b438
+	rc = tsocket_address_inet_from_strings(frame,
b6b438
 					       "ip",
b6b438
 					       "127.0.0.1",
b6b438
 					       0,
b6b438
@@ -1154,7 +1155,7 @@ static NTSTATUS netr_set_machine_account_password(TALLOC_CTX *mem_ctx,
b6b438
 		goto out;
b6b438
 	}
b6b438
 
b6b438
-	status = rpcint_binding_handle(mem_ctx,
b6b438
+	status = rpcint_binding_handle(frame,
b6b438
 				       &ndr_table_samr,
b6b438
 				       local,
b6b438
 				       NULL,
b6b438
@@ -1166,7 +1167,7 @@ static NTSTATUS netr_set_machine_account_password(TALLOC_CTX *mem_ctx,
b6b438
 	}
b6b438
 
b6b438
 	become_root();
b6b438
-	status = samr_find_machine_account(mem_ctx,
b6b438
+	status = samr_find_machine_account(frame,
b6b438
 					   h,
b6b438
 					   account_name,
b6b438
 					   SEC_FLAG_MAXIMUM_ALLOWED,
b6b438
@@ -1179,7 +1180,7 @@ static NTSTATUS netr_set_machine_account_password(TALLOC_CTX *mem_ctx,
b6b438
 	}
b6b438
 
b6b438
 	status = dcerpc_samr_QueryUserInfo2(h,
b6b438
-					    mem_ctx,
b6b438
+					    frame,
b6b438
 					    &user_handle,
b6b438
 					    UserControlInformation,
b6b438
 					    &info,
b6b438
@@ -1213,7 +1214,11 @@ static NTSTATUS netr_set_machine_account_password(TALLOC_CTX *mem_ctx,
b6b438
 			infolevel = UserInternal1Information;
b6b438
 
b6b438
 			in = data_blob_const(cr->creds.nt_hash, 16);
b6b438
-			out = data_blob_talloc_zero(mem_ctx, 16);
b6b438
+			out = data_blob_talloc_zero(frame, 16);
b6b438
+			if (out.data == NULL) {
b6b438
+				status = NT_STATUS_NO_MEMORY;
b6b438
+				goto out;
b6b438
+			}
b6b438
 			sess_crypt_blob(&out, &in, &session_key, true);
b6b438
 			memcpy(info18.nt_pwd.hash, out.data, out.length);
b6b438
 
b6b438
@@ -1244,7 +1249,7 @@ static NTSTATUS netr_set_machine_account_password(TALLOC_CTX *mem_ctx,
b6b438
 
b6b438
 	become_root();
b6b438
 	status = dcerpc_samr_SetUserInfo2(h,
b6b438
-					  mem_ctx,
b6b438
+					  frame,
b6b438
 					  &user_handle,
b6b438
 					  infolevel,
b6b438
 					  info,
b6b438
@@ -1260,8 +1265,9 @@ static NTSTATUS netr_set_machine_account_password(TALLOC_CTX *mem_ctx,
b6b438
 
b6b438
  out:
b6b438
 	if (h && is_valid_policy_hnd(&user_handle)) {
b6b438
-		dcerpc_samr_Close(h, mem_ctx, &user_handle, &result);
b6b438
+		dcerpc_samr_Close(h, frame, &user_handle, &result);
b6b438
 	}
b6b438
+	TALLOC_FREE(frame);
b6b438
 
b6b438
 	return status;
b6b438
 }
b6b438
-- 
b6b438
2.23.0
b6b438