ctdb-protocol: Fix marshalling for ctdb_event_request
authorAmitay Isaacs <amitay@gmail.com>
Mon, 7 Aug 2017 07:55:50 +0000 (17:55 +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 3a1a6eb4d9177470ccd839c7dd6126f7531048cc..83aa24e731fd152a1da2526e78c623c205563020 100644 (file)
@@ -873,6 +873,11 @@ int ctdb_event_request_push(struct ctdb_event_request *in,
        offset += np;
 
        ctdb_event_request_data_push(&in->rdata, buf+offset, &np);
+       offset += np;
+
+       if (offset > *buflen) {
+               return EMSGSIZE;
+       }
 
        return 0;
 }
@@ -895,6 +900,11 @@ int ctdb_event_request_pull(uint8_t *buf, size_t buflen,
        if (ret != 0) {
                return ret;
        }
+       offset += np;
+
+       if (offset > buflen) {
+               return EMSGSIZE;
+       }
 
        return 0;
 }
index 1d3f12a3eee72792e6d7ad7b8349437fdc6ad82a..7ba1cc59200117f6a08c700716c9bed1ec7127c0 100755 (executable)
@@ -22,8 +22,7 @@ output=$(
     echo "ctdb_event_header"
     generate_output "ctdb_event_request_data"
     generate_output "ctdb_event_reply_data"
-    echo "ctdb_event_request"
-    echo "$command_output"
+    generate_output "ctdb_event_request"
     echo "ctdb_event_reply"
     echo "$command_output"
 )
index f5cd981d8071d981973cae8dfa826d00d87c83f6..08314d4a6c87c46033679cfc961c6114feef6ac8 100644 (file)
@@ -124,46 +124,6 @@ static void test_ctdb_event_header(void)
 
 #define NUM_COMMANDS   5
 
-static void test_ctdb_event_request(void)
-{
-       TALLOC_CTX *mem_ctx;
-       uint8_t *buf;
-       size_t len, buflen;
-       int ret;
-       struct ctdb_event_request r, r2;
-       uint32_t command;
-
-       printf("ctdb_event_request\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_request(mem_ctx, &r, command);
-               buflen = ctdb_event_request_len(&r);
-               buf = talloc_size(mem_ctx, buflen);
-               assert(buf != NULL);
-               len = 0;
-               ret = ctdb_event_request_push(&r, buf, &len);
-               assert(ret == EMSGSIZE);
-               assert(len == buflen);
-               ret = ctdb_event_request_push(&r, buf, &buflen);
-               assert(ret == 0);
-               ret = ctdb_event_request_pull(buf, buflen, mem_ctx, &r2);
-               assert(ret == 0);
-               assert(r2.header.length == buflen);
-               verify_ctdb_event_request(&r, &r2);
-
-               talloc_free(mem_ctx);
-       }
-
-       printf("\n");
-       fflush(stdout);
-}
-
 static void test_ctdb_event_reply(void)
 {
        TALLOC_CTX *mem_ctx;
@@ -217,6 +177,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);
 
 int main(int argc, char *argv[])
 {
@@ -242,7 +203,10 @@ int main(int argc, char *argv[])
        for (command=1; command<=NUM_COMMANDS; command++) {
                TEST_FUNC(ctdb_event_reply_data)(command);
        }
-       test_ctdb_event_request();
+
+       for (command=1; command<=NUM_COMMANDS; command++) {
+               TEST_FUNC(ctdb_event_request)(command);
+       }
        test_ctdb_event_reply();
 
        return 0;