From: Jeremy Allison Date: Wed, 26 Aug 2020 22:16:48 +0000 (-0700) Subject: s3: libsmb: Change remove_duplicate_addrs2() to take and return size_t, not int. X-Git-Tag: talloc-2.3.2~597 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=aa20df217c4601ce8243f4d51eeed12c4d6cfb1d;p=thirdparty%2Fsamba.git s3: libsmb: Change remove_duplicate_addrs2() to take and return size_t, not int. Will make converting _internal_resolve_name() to return a size_t easier. Signed-off-by: Jeremy Allison Reviewed-by: Noel Power --- diff --git a/source3/libsmb/namequery.c b/source3/libsmb/namequery.c index fe4dd2774b1..688e62d64fc 100644 --- a/source3/libsmb/namequery.c +++ b/source3/libsmb/namequery.c @@ -1213,9 +1213,9 @@ static void sort_service_list(struct ip_service *servlist, int count) Remove any duplicate address/port pairs in the list *********************************************************************/ -int remove_duplicate_addrs2(struct ip_service *iplist, int count ) +size_t remove_duplicate_addrs2(struct ip_service *iplist, size_t count ) { - int i, j; + size_t i, j; DEBUG(10,("remove_duplicate_addrs2: " "looking for duplicate address/port pairs\n")); @@ -3234,7 +3234,6 @@ static NTSTATUS _internal_resolve_name(const char *name, if (ok) { *return_count = remove_duplicate_addrs2(*return_iplist, *return_count ); - /* This could be a negative response */ if (*return_count > 0) { TALLOC_FREE(frame); return NT_STATUS_OK; @@ -3379,7 +3378,15 @@ static NTSTATUS _internal_resolve_name(const char *name, controllers including the PDC in iplist[1..n]. Iterating over the iplist when the PDC is down will cause two sets of timeouts. */ - *return_count = remove_duplicate_addrs2(*return_iplist, *return_count ); + *return_count = (int)remove_duplicate_addrs2(*return_iplist, + *return_count ); + /* Paranoia casting size_t -> int. */ + if (*return_count < 0) { + SAFE_FREE(*return_iplist); + *return_count = 0; + TALLOC_FREE(frame); + return NT_STATUS_INVALID_PARAMETER; + } /* Save in name cache */ if ( DEBUGLEVEL >= 100 ) { diff --git a/source3/libsmb/namequery.h b/source3/libsmb/namequery.h index b491616b87e..e8df065c7e9 100644 --- a/source3/libsmb/namequery.h +++ b/source3/libsmb/namequery.h @@ -47,7 +47,7 @@ bool name_status_find(const char *q_name, int type, const struct sockaddr_storage *to_ss, fstring name); -int remove_duplicate_addrs2(struct ip_service *iplist, int count ); +size_t remove_duplicate_addrs2(struct ip_service *iplist, size_t count ); struct tevent_req *name_query_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, const char *name, int name_type, diff --git a/source3/torture/torture.c b/source3/torture/torture.c index d2dedd8938f..b4ad36127f5 100644 --- a/source3/torture/torture.c +++ b/source3/torture/torture.c @@ -14020,7 +14020,7 @@ static const char *remove_duplicate_addrs2_test_strings_result[] = { static bool run_local_remove_duplicate_addrs2(int dummy) { struct ip_service test_vector[28]; - int count, i; + size_t count, i; /* Construct the sockaddr_storage test vector. */ for (i = 0; i < 28; i++) { @@ -14049,7 +14049,7 @@ static bool run_local_remove_duplicate_addrs2(int dummy) count = remove_duplicate_addrs2(test_vector, i); if (count != 14) { - fprintf(stderr, "count wrong (%d) should be 14\n", + fprintf(stderr, "count wrong (%zu) should be 14\n", count); return false; } @@ -14060,7 +14060,7 @@ static bool run_local_remove_duplicate_addrs2(int dummy) print_sockaddr(addr, sizeof(addr), &test_vector[i].ss); if (strcmp(addr, remove_duplicate_addrs2_test_strings_result[i]) != 0) { - fprintf(stderr, "mismatch on [%d] [%s] [%s]\n", + fprintf(stderr, "mismatch on [%zu] [%s] [%s]\n", i, addr, remove_duplicate_addrs2_test_strings_result[i]);