ctdb-protocol: Fix marshalling of struct ctdb_public_ip_list
authorAmitay Isaacs <amitay@gmail.com>
Fri, 6 Nov 2015 03:27:33 +0000 (14:27 +1100)
committerMartin Schwenke <martins@samba.org>
Wed, 25 Nov 2015 09:16:20 +0000 (10:16 +0100)
There can be 0 public addresses.

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Jeremy Allison <jra@samba.org>
ctdb/protocol/protocol_types.c
ctdb/tests/src/protocol_types_test.c

index d52e945f5be5c8068d20c3454cd3644a5ee2967a..fc7c43380cbc45c2bb4da0380f9c8404e072c38e 100644 (file)
@@ -1675,6 +1675,11 @@ int ctdb_public_ip_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
        }
 
        pubip_list->num = wire->num;
+       if (wire->num == 0) {
+               pubip_list->ip = NULL;
+               *out = pubip_list;
+               return 0;
+       }
        pubip_list->ip = talloc_array(pubip_list, struct ctdb_public_ip,
                                      wire->num);
        if (pubip_list->ip == NULL) {
index b4543248a98073ff8843a21eb18c6375e63092c0..1d3eb94dd04f75321b53ea24fd81e6c0b5ebfd48 100644 (file)
@@ -611,7 +611,11 @@ static void fill_ctdb_public_ip_list(TALLOC_CTX *mem_ctx,
 {
        int i;
 
-       p->num = rand_int(32) + 1;
+       p->num = rand_int(32);
+       if (p->num == 0) {
+               p->ip = NULL;
+               return;
+       }
        p->ip = talloc_array(mem_ctx, struct ctdb_public_ip, p->num);
        assert(p->ip != NULL);
        for (i=0; i<p->num; i++) {