mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-07-29 13:01:13 +03:00
tests: Check buffer bignum behaviour.
Signed-off-by: Simon Josefsson <simon@josefsson.org> Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Sahana Prasad <sahana@redhat.com>
This commit is contained in:
committed by
Jakub Jelen
parent
fbf02d5936
commit
7e3263d995
@ -259,17 +259,64 @@ static void torture_buffer_pack_badformat(void **state){
|
|||||||
* it could crash the process */
|
* it could crash the process */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void torture_ssh_buffer_bignum(void **state)
|
||||||
|
{
|
||||||
|
ssh_buffer buffer = NULL;
|
||||||
|
bignum num = NULL;
|
||||||
|
int rc;
|
||||||
|
size_t len;
|
||||||
|
uint8_t verif[] = "\x00\x00\x00\x04" /* len 4 byte */
|
||||||
|
"\x00\x00\x00\xff" /* padded 255 */
|
||||||
|
"\x00\x00\x00\x02" /* len 2 byte */
|
||||||
|
"\x00\xff"; /* padded 255 */
|
||||||
|
|
||||||
|
(void)state;
|
||||||
|
|
||||||
|
buffer = ssh_buffer_new();
|
||||||
|
assert_non_null(buffer);
|
||||||
|
|
||||||
|
num = bignum_new();
|
||||||
|
assert_non_null(num);
|
||||||
|
assert_int_equal(1, bignum_set_word(num, 255));
|
||||||
|
|
||||||
|
rc = ssh_buffer_pack(buffer, "FB", num, (size_t)4, num);
|
||||||
|
assert_int_equal(rc, SSH_OK);
|
||||||
|
|
||||||
|
bignum_safe_free(num);
|
||||||
|
|
||||||
|
len = ssh_buffer_get_len(buffer);
|
||||||
|
assert_int_equal(len, sizeof(verif) - 1);
|
||||||
|
assert_memory_equal(ssh_buffer_get(buffer), verif, sizeof(verif) - 1);
|
||||||
|
|
||||||
|
SSH_BUFFER_FREE(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
int torture_run_tests(void) {
|
int torture_run_tests(void) {
|
||||||
int rc;
|
int rc;
|
||||||
struct CMUnitTest tests[] = {
|
struct CMUnitTest tests[] = {
|
||||||
cmocka_unit_test_setup_teardown(torture_growing_buffer, setup, teardown),
|
cmocka_unit_test_setup_teardown(torture_growing_buffer,
|
||||||
cmocka_unit_test_setup_teardown(torture_growing_buffer_shifting, setup, teardown),
|
setup,
|
||||||
cmocka_unit_test_setup_teardown(torture_buffer_prepend, setup, teardown),
|
teardown),
|
||||||
|
cmocka_unit_test_setup_teardown(torture_growing_buffer_shifting,
|
||||||
|
setup,
|
||||||
|
teardown),
|
||||||
|
cmocka_unit_test_setup_teardown(torture_buffer_prepend,
|
||||||
|
setup,
|
||||||
|
teardown),
|
||||||
cmocka_unit_test(torture_ssh_buffer_get_ssh_string),
|
cmocka_unit_test(torture_ssh_buffer_get_ssh_string),
|
||||||
cmocka_unit_test_setup_teardown(torture_ssh_buffer_add_format, setup, teardown),
|
cmocka_unit_test_setup_teardown(torture_ssh_buffer_add_format,
|
||||||
cmocka_unit_test_setup_teardown(torture_ssh_buffer_get_format, setup, teardown),
|
setup,
|
||||||
cmocka_unit_test_setup_teardown(torture_ssh_buffer_get_format_error, setup, teardown),
|
teardown),
|
||||||
cmocka_unit_test_setup_teardown(torture_buffer_pack_badformat, setup, teardown)
|
cmocka_unit_test_setup_teardown(torture_ssh_buffer_get_format,
|
||||||
|
setup,
|
||||||
|
teardown),
|
||||||
|
cmocka_unit_test_setup_teardown(torture_ssh_buffer_get_format_error,
|
||||||
|
setup,
|
||||||
|
teardown),
|
||||||
|
cmocka_unit_test_setup_teardown(torture_buffer_pack_badformat,
|
||||||
|
setup,
|
||||||
|
teardown),
|
||||||
|
cmocka_unit_test(torture_ssh_buffer_bignum),
|
||||||
};
|
};
|
||||||
|
|
||||||
ssh_init();
|
ssh_init();
|
||||||
|
Reference in New Issue
Block a user