diff options
| author | Garrett D'Amore <garrett@damore.org> | 2019-12-31 15:09:20 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2020-01-01 08:47:06 -0800 |
| commit | a693a53e2302fe9cc60c1b5d2bf59c42032b20a3 (patch) | |
| tree | e98ba805ea9adc2e5ee3e33f7dea1c32584d5c63 /src/protocol/reqrep0/reqrep_test.c | |
| parent | 0ab3403ef9407db4604cbb451c42a179ab807342 (diff) | |
| download | nng-a693a53e2302fe9cc60c1b5d2bf59c42032b20a3.tar.gz nng-a693a53e2302fe9cc60c1b5d2bf59c42032b20a3.tar.bz2 nng-a693a53e2302fe9cc60c1b5d2bf59c42032b20a3.zip | |
fixes #1081 Use after free possible in stats
fixes #1080 Desire better way to access statistics for NNG objects
We've also added a test that uses some of this, in order to verify
that the req protocol rejects invalid peers.
Diffstat (limited to 'src/protocol/reqrep0/reqrep_test.c')
| -rw-r--r-- | src/protocol/reqrep0/reqrep_test.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/protocol/reqrep0/reqrep_test.c b/src/protocol/reqrep0/reqrep_test.c index b68c08cb..f4617936 100644 --- a/src/protocol/reqrep0/reqrep_test.c +++ b/src/protocol/reqrep0/reqrep_test.c @@ -387,6 +387,37 @@ test_req_context_not_pollable(void) TEST_NNG_PASS(nng_close(req)); } +void +test_req_validate_peer(void) +{ + nng_socket s1, s2; + nng_stat * stats; + nng_stat * reject; + char addr[64]; + + testutil_scratch_addr("inproc", sizeof(addr), addr); + + TEST_NNG_PASS(nng_req0_open(&s1)); + TEST_NNG_PASS(nng_req0_open(&s2)); + + TEST_NNG_PASS(nng_listen(s1, addr, NULL, 0)); + TEST_NNG_PASS(nng_dial(s2, addr, NULL, NNG_FLAG_NONBLOCK)); + + testutil_sleep(100); + TEST_NNG_PASS(nng_stats_get(&stats)); + + TEST_CHECK(stats != NULL); + TEST_CHECK((reject = nng_stat_find_socket(stats, s1)) != NULL); + TEST_CHECK((reject = nng_stat_find(reject, "reject")) != NULL); + + TEST_CHECK(nng_stat_type(reject) == NNG_STAT_COUNTER); + TEST_CHECK(nng_stat_value(reject) > 0); + + TEST_NNG_PASS(nng_close(s1)); + TEST_NNG_PASS(nng_close(s2)); + nng_stats_free(stats); +} + TEST_LIST = { { "req rep identity", test_req_rep_identity }, { "resend option", test_resend_option }, @@ -398,5 +429,6 @@ TEST_LIST = { { "req poll writable", test_req_poll_writeable }, { "req poll readable", test_req_poll_readable }, { "req context not pollable", test_req_context_not_pollable }, + { "req validate peer", test_req_validate_peer }, { NULL, NULL }, }; |
