lib: addns: Fix ads_dns_lookup_srv() and functions to return size_t * num servers.
[amitay/samba.git] / source4 / libcli / resolve / dns_ex.c
index a2e5551ea260889dc1c8337b906be1dca0320b1e..0bb3ba022872c5cf696665b9c914e49b4e519181 100644 (file)
@@ -268,13 +268,13 @@ done:
 static struct dns_records_container get_srv_records(TALLOC_CTX *mem_ctx,
                                                        const char* name)
 {
-       struct dns_records_container ret;
+       struct dns_records_container ret = {0};
        char **addrs = NULL;
        struct dns_rr_srv *dclist;
        NTSTATUS status;
-       uint32_t total;
-       int i;
-       int count;
+       size_t total;
+       size_t i;
+       size_t count = 0;
 
        memset(&ret, 0, sizeof(struct dns_records_container));
        /* this is the blocking call we are going to lots of trouble
@@ -303,6 +303,13 @@ static struct dns_records_container get_srv_records(TALLOC_CTX *mem_ctx,
                }
 
                c = get_a_aaaa_records(mem_ctx, tmp_str, dclist[i].port);
+
+               /* wrap check */
+               if (total + c.count < total) {
+                       /* possibly could just break here instead? */
+                       TALLOC_FREE(addrs);
+                       return ret;
+               }
                total += c.count;
                if (addrs == NULL) {
                        addrs = c.list;