From b107397d8bbb767127807ee86ce88d0e14a53f09 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Mon, 7 Aug 2017 17:55:50 +1000 Subject: [PATCH] ctdb-protocol: Fix marshalling for ctdb_event_request Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke --- ctdb/protocol/protocol_event.c | 10 ++++++ ctdb/tests/cunit/protocol_test_102.sh | 3 +- ctdb/tests/src/protocol_event_test.c | 46 +++------------------------ 3 files changed, 16 insertions(+), 43 deletions(-) diff --git a/ctdb/protocol/protocol_event.c b/ctdb/protocol/protocol_event.c index 3a1a6eb4d91..83aa24e731f 100644 --- a/ctdb/protocol/protocol_event.c +++ b/ctdb/protocol/protocol_event.c @@ -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; } diff --git a/ctdb/tests/cunit/protocol_test_102.sh b/ctdb/tests/cunit/protocol_test_102.sh index 1d3f12a3eee..7ba1cc59200 100755 --- a/ctdb/tests/cunit/protocol_test_102.sh +++ b/ctdb/tests/cunit/protocol_test_102.sh @@ -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" ) diff --git a/ctdb/tests/src/protocol_event_test.c b/ctdb/tests/src/protocol_event_test.c index f5cd981d807..08314d4a6c8 100644 --- a/ctdb/tests/src/protocol_event_test.c +++ b/ctdb/tests/src/protocol_event_test.c @@ -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; -- 2.34.1