pki: Fix random memory corruption

Fixes T78

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
Andreas Schneider
2018-06-29 09:22:26 +02:00
parent aa95eb1965
commit 1444ae5add
3 changed files with 23 additions and 4 deletions

View File

@@ -31,6 +31,8 @@ static int setup_rsa_key(void **state)
torture_get_testkey(SSH_KEYTYPE_RSA, 0, 1));
torture_write_file(LIBSSH_RSA_TESTKEY ".pub",
torture_get_testkey_pub(SSH_KEYTYPE_RSA, 0));
torture_write_file(LIBSSH_RSA_TESTKEY ".pub",
torture_get_testkey_pub(SSH_KEYTYPE_RSA, 0));
torture_write_file(LIBSSH_RSA_TESTKEY "-cert.pub",
torture_get_testkey_pub(SSH_KEYTYPE_RSA_CERT01, 0));
@@ -48,6 +50,21 @@ static int teardown(void **state) {
return 0;
}
static void torture_pki_rsa_import_pubkey_file(void **state)
{
ssh_key pubkey = NULL;
int rc;
(void)state;
/* The key doesn't have the hostname as comment after the key */
rc = ssh_pki_import_pubkey_file(LIBSSH_RSA_TESTKEY ".pub", &pubkey);
assert_return_code(rc, errno);
assert_non_null(pubkey);
ssh_key_free(pubkey);
}
static void torture_pki_rsa_import_privkey_base64_NULL_key(void **state)
{
int rc;
@@ -546,6 +563,9 @@ static void torture_pki_rsa_import_privkey_base64_passphrase(void **state)
int torture_run_tests(void) {
int rc;
struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(torture_pki_rsa_import_pubkey_file,
setup_rsa_key,
teardown),
cmocka_unit_test_setup_teardown(torture_pki_rsa_import_privkey_base64_NULL_key,
setup_rsa_key,
teardown),