diff options
-rw-r--r-- | ctdb/protocol/protocol_event.c | 10 | ||||
-rwxr-xr-x | ctdb/tests/cunit/protocol_test_102.sh | 10 | ||||
-rw-r--r-- | ctdb/tests/src/protocol_event_test.c | 45 |
3 files changed, 15 insertions, 50 deletions
diff --git a/ctdb/protocol/protocol_event.c b/ctdb/protocol/protocol_event.c index 83aa24e731f..b1a7498be08 100644 --- a/ctdb/protocol/protocol_event.c +++ b/ctdb/protocol/protocol_event.c @@ -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; } diff --git a/ctdb/tests/cunit/protocol_test_102.sh b/ctdb/tests/cunit/protocol_test_102.sh index 7ba1cc59200..898a43dc7c1 100755 --- a/ctdb/tests/cunit/protocol_test_102.sh +++ b/ctdb/tests/cunit/protocol_test_102.sh @@ -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" diff --git a/ctdb/tests/src/protocol_event_test.c b/ctdb/tests/src/protocol_event_test.c index 08314d4a6c8..63d53011905 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_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; } |