From d8ff36520f3e3914a6f5c7cc8d569e863023bcfc Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 8 Sep 2020 15:58:07 -0700 Subject: [PATCH] s3: libsmb: Fix the count returns in discover_dc_netbios(), discover_dc_dns(), process_dc_dns() to return size_t * counts. Signed-off-by: Jeremy Allison Reviewed-by: Noel Power --- source3/libsmb/dsgetdcname.c | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/source3/libsmb/dsgetdcname.c b/source3/libsmb/dsgetdcname.c index 4d037984fc8..c7f26465e8f 100644 --- a/source3/libsmb/dsgetdcname.c +++ b/source3/libsmb/dsgetdcname.c @@ -439,14 +439,14 @@ static NTSTATUS discover_dc_netbios(TALLOC_CTX *mem_ctx, const char *domain_name, uint32_t flags, struct ip_service_name **returned_dclist, - int *returned_count) + size_t *returned_count) { NTSTATUS status; enum nbt_name_type name_type = NBT_NAME_LOGON; struct ip_service *iplist = NULL; size_t i; struct ip_service_name *dclist = NULL; - size_t count; + size_t count = 0; static const char *resolve_order[] = { "lmhosts", "wins", "bcast", NULL }; if (flags & DS_PDC_REQUIRED) { @@ -496,12 +496,6 @@ static NTSTATUS discover_dc_netbios(TALLOC_CTX *mem_ctx, TALLOC_FREE(iplist); - /* Paranoia in casting size_t -> int. */ - if ((int)count < 0) { - TALLOC_FREE(dclist); - return NT_STATUS_INVALID_PARAMETER; - } - *returned_dclist = dclist; *returned_count = count; @@ -517,7 +511,7 @@ static NTSTATUS discover_dc_dns(TALLOC_CTX *mem_ctx, uint32_t flags, const char *site_name, struct ip_service_name **returned_dclist, - int *return_count) + size_t *return_count) { size_t i; NTSTATUS status; @@ -769,20 +763,11 @@ static NTSTATUS discover_dc_dns(TALLOC_CTX *mem_ctx, } } - - if ((int)ret_count < 0) { - TALLOC_FREE(dcs); - TALLOC_FREE(dclist); - TALLOC_FREE(dns_lookups); - return NT_STATUS_INTERNAL_ERROR; - } - - if (ret_count > 0) { TALLOC_FREE(dcs); TALLOC_FREE(dns_lookups); *returned_dclist = dclist; - *return_count = (int)ret_count; + *return_count = ret_count; return NT_STATUS_OK; } @@ -999,10 +984,10 @@ static NTSTATUS process_dc_dns(TALLOC_CTX *mem_ctx, const char *domain_name, uint32_t flags, struct ip_service_name *dclist, - int num_dcs, + size_t num_dcs, struct netr_DsRGetDCNameInfo **info) { - int i = 0; + size_t i = 0; bool valid_dc = false; struct netlogon_samlogon_response *r = NULL; uint32_t nt_version = NETLOGON_NT_VERSION_5 | @@ -1061,12 +1046,12 @@ static NTSTATUS process_dc_netbios(TALLOC_CTX *mem_ctx, const char *domain_name, uint32_t flags, struct ip_service_name *dclist, - int num_dcs, + size_t num_dcs, struct netr_DsRGetDCNameInfo **info) { enum nbt_name_type name_type = NBT_NAME_LOGON; NTSTATUS status; - int i; + size_t i; const char *dc_name = NULL; fstring tmp_dc_name; struct netlogon_samlogon_response *r = NULL; @@ -1172,7 +1157,7 @@ static NTSTATUS dsgetdcname_rediscover(TALLOC_CTX *mem_ctx, { NTSTATUS status; struct ip_service_name *dclist = NULL; - int num_dcs; + size_t num_dcs = 0; DEBUG(10,("dsgetdcname_rediscover\n")); -- 2.47.3