diff options
author | Aris Adamantiadis <aris@0xbadc0de.be> | 2014-04-22 23:00:32 +0200 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2014-08-06 10:00:07 +0200 |
commit | 664b94d1c54b89b313c1b4ab52fecc40202b3dde (patch) | |
tree | ed91b2f177ddb32e41380bcb14467d7c64d6285f /tests/unittests | |
parent | 3b4b0f01ecdc8b24cb10d871f200abb26bef1548 (diff) | |
download | libssh-664b94d1c54b89b313c1b4ab52fecc40202b3dde.tar.gz libssh-664b94d1c54b89b313c1b4ab52fecc40202b3dde.tar.xz libssh-664b94d1c54b89b313c1b4ab52fecc40202b3dde.zip |
tests: test the canary feature in buffer_(un)pack()
Reviewed-by: Andreas Schneider <asn@samba.org>
Diffstat (limited to 'tests/unittests')
-rw-r--r-- | tests/unittests/torture_buffer.c | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/tests/unittests/torture_buffer.c b/tests/unittests/torture_buffer.c index f4fa465e..2230386f 100644 --- a/tests/unittests/torture_buffer.c +++ b/tests/unittests/torture_buffer.c @@ -219,6 +219,31 @@ static void torture_buffer_get_format_error(void **state) { assert_true(s2 == NULL); } +static void torture_buffer_pack_badformat(void **state){ + ssh_buffer buffer = *state; + uint8_t b = 42; + int rc; + + /* first with missing format */ + rc = ssh_buffer_pack(buffer, "b", b, b); + assert_int_equal(rc, SSH_ERROR); + ssh_buffer_reinit(buffer); + + /* with additional format */ + rc = ssh_buffer_pack(buffer, "bb", b); + assert_int_equal(rc, SSH_ERROR); + + /* unpack with missing format */ + ssh_buffer_reinit(buffer); + rc = ssh_buffer_pack(buffer, "bb", 42, 43); + assert_int_equal(rc, SSH_OK); + rc = ssh_buffer_unpack(buffer, "b", &b, &b); + assert_int_equal(rc, SSH_ERROR); + + /* not doing the test with additional format as + * it could crash the process */ +} + int torture_run_tests(void) { int rc; const UnitTest tests[] = { @@ -228,7 +253,8 @@ int torture_run_tests(void) { unit_test(torture_buffer_get_ssh_string), unit_test_setup_teardown(torture_buffer_add_format, setup, teardown), unit_test_setup_teardown(torture_buffer_get_format, setup, teardown), - unit_test_setup_teardown(torture_buffer_get_format_error, setup, teardown) + unit_test_setup_teardown(torture_buffer_get_format_error, setup, teardown), + unit_test_setup_teardown(torture_buffer_pack_badformat, setup, teardown) }; ssh_init(); |