ctdb-protocol: Fix marshalling of ctdb_event_reply
authorAmitay Isaacs <amitay@gmail.com>
Mon, 7 Aug 2017 08:00:04 +0000 (18:00 +1000)
committerMartin Schwenke <martins@samba.org>
Wed, 30 Aug 2017 12:59:26 +0000 (14:59 +0200)
Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
ctdb/protocol/protocol_event.c
ctdb/tests/cunit/protocol_test_102.sh
ctdb/tests/src/protocol_event_test.c

index 83aa24e731fd152a1da2526e78c623c205563020..b1a7498be08301a06b06381e9777faed2000400c 100644 (file)
@@ -932,6 +932,11 @@ int ctdb_event_reply_push(struct ctdb_event_reply *in,
        offset += np;
 
        ctdb_event_reply_data_push(&in->rdata, buf+offset, &np);
+       offset += np;
+
+       if (offset > *buflen) {
+               return EMSGSIZE;
+       }
 
        return 0;
 }
@@ -954,6 +959,11 @@ int ctdb_event_reply_pull(uint8_t *buf, size_t buflen,
        if (ret != 0) {
                return ret;
        }
+       offset += np;
+
+       if (offset > buflen) {
+               return EMSGSIZE;
+       }
 
        return 0;
 }
index 7ba1cc59200117f6a08c700716c9bed1ec7127c0..898a43dc7c1ef14fd04b66305ab2edee83004df3 100755 (executable)
@@ -4,13 +4,6 @@
 
 last_command=5
 
-command_output=$(
-    for i in $(seq 1 $last_command) ; do
-       echo -n "$i.. "
-    done
-    echo
-)
-
 generate_output ()
 {
     for i in $(seq 1 $last_command) ; do
@@ -23,8 +16,7 @@ output=$(
     generate_output "ctdb_event_request_data"
     generate_output "ctdb_event_reply_data"
     generate_output "ctdb_event_request"
-    echo "ctdb_event_reply"
-    echo "$command_output"
+    generate_output "ctdb_event_reply"
 )
 
 ok "$output"
index 08314d4a6c87c46033679cfc961c6114feef6ac8..63d53011905688d3a34029413c181542baa68004 100644 (file)
@@ -124,46 +124,6 @@ static void test_ctdb_event_header(void)
 
 #define NUM_COMMANDS   5
 
-static void test_ctdb_event_reply(void)
-{
-       TALLOC_CTX *mem_ctx;
-       uint8_t *buf;
-       size_t len, buflen;
-       int ret;
-       struct ctdb_event_reply r, r2;
-       uint32_t command;
-
-       printf("ctdb_event_reply\n");
-       fflush(stdout);
-
-       for (command=1; command<=NUM_COMMANDS; command++) {
-               mem_ctx = talloc_new(NULL);
-               assert(mem_ctx != NULL);
-
-               printf("%u.. ", command);
-               fflush(stdout);
-               fill_ctdb_event_reply(mem_ctx, &r, command);
-               buflen = ctdb_event_reply_len(&r);
-               buf = talloc_size(mem_ctx, buflen);
-               assert(buf != NULL);
-               len = 0;
-               ret = ctdb_event_reply_push(&r, buf, &len);
-               assert(ret == EMSGSIZE);
-               assert(len == buflen);
-               ret = ctdb_event_reply_push(&r, buf, &buflen);
-               assert(ret == 0);
-               ret = ctdb_event_reply_pull(buf, buflen, mem_ctx, &r2);
-               assert(ret == 0);
-               assert(r2.header.length == buflen);
-               verify_ctdb_event_reply(&r, &r2);
-
-               talloc_free(mem_ctx);
-       }
-
-       printf("\n");
-       fflush(stdout);
-}
-
 PROTOCOL_TYPE3_TEST(struct ctdb_event_request_run, ctdb_event_request_run);
 PROTOCOL_TYPE3_TEST(struct ctdb_event_request_status,
                                ctdb_event_request_status);
@@ -178,6 +138,7 @@ PROTOCOL_TYPE3_TEST(struct ctdb_event_reply_script_list,
 PROTOCOL_EVENT1_TEST(struct ctdb_event_request_data, ctdb_event_request_data);
 PROTOCOL_EVENT1_TEST(struct ctdb_event_reply_data, ctdb_event_reply_data);
 PROTOCOL_EVENT2_TEST(struct ctdb_event_request, ctdb_event_request);
+PROTOCOL_EVENT2_TEST(struct ctdb_event_reply, ctdb_event_reply);
 
 int main(int argc, char *argv[])
 {
@@ -207,7 +168,9 @@ int main(int argc, char *argv[])
        for (command=1; command<=NUM_COMMANDS; command++) {
                TEST_FUNC(ctdb_event_request)(command);
        }
-       test_ctdb_event_reply();
+       for (command=1; command<=NUM_COMMANDS; command++) {
+               TEST_FUNC(ctdb_event_reply)(command);
+       }
 
        return 0;
 }