s3: libsmb: Change remove_duplicate_addrs2() to take and return size_t, not int.
authorJeremy Allison <jra@samba.org>
Wed, 26 Aug 2020 22:16:48 +0000 (15:16 -0700)
committerNoel Power <npower@samba.org>
Mon, 7 Sep 2020 13:23:42 +0000 (13:23 +0000)
Will make converting _internal_resolve_name() to return a size_t easier.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
source3/libsmb/namequery.c
source3/libsmb/namequery.h
source3/torture/torture.c

index fe4dd2774b1ff64084118ac6a9a70daa523062d8..688e62d64fc1902db9428704018edecb45c8c88d 100644 (file)
@@ -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 ) {
index b491616b87eee9023b700504dcd95b96fa681c04..e8df065c7e9925bb3410b2589a62fffa790670d0 100644 (file)
@@ -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,
index d2dedd8938fedcf7c61177cd3eaef5e61eb3af81..b4ad36127f534ac912eabf29d76076e9664b58d8 100644 (file)
@@ -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]);