mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-08-08 19:02:06 +03:00
pki: Fix random memory corruption
Fixes T78 Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
@@ -1084,7 +1084,7 @@ int ssh_pki_import_pubkey_file(const char *filename, ssh_key *pkey)
|
|||||||
key_buf[size] = '\0';
|
key_buf[size] = '\0';
|
||||||
|
|
||||||
q = p = key_buf;
|
q = p = key_buf;
|
||||||
while (!isspace((int)*p)) p++;
|
while (*p != '\0' && !isspace((int)*p)) p++;
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
|
|
||||||
type = ssh_key_type_from_name(q);
|
type = ssh_key_type_from_name(q);
|
||||||
@@ -1093,7 +1093,7 @@ int ssh_pki_import_pubkey_file(const char *filename, ssh_key *pkey)
|
|||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
}
|
}
|
||||||
q = ++p;
|
q = ++p;
|
||||||
while (!isspace((int)*p)) p++;
|
while (*p != '\0' && !isspace((int)*p)) p++;
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
|
|
||||||
rc = ssh_pki_import_pubkey_base64(q, type, pkey);
|
rc = ssh_pki_import_pubkey_base64(q, type, pkey);
|
||||||
|
@@ -170,8 +170,7 @@ static const char torture_dsa_public_testkey[] =
|
|||||||
"AQDM+JcO6XTMdyXTKIo+tGsuA0kd4pxPol+UGeAruNBEhVSDcXfXTh9tVravBqeIuX"
|
"AQDM+JcO6XTMdyXTKIo+tGsuA0kd4pxPol+UGeAruNBEhVSDcXfXTh9tVravBqeIuX"
|
||||||
"gZIFk9cylR2eDwAAAIB4roDQBfgf8AoSAJAb7y8OVvxt5cT7iqaRMQX2XgtW09Nu9R"
|
"gZIFk9cylR2eDwAAAIB4roDQBfgf8AoSAJAb7y8OVvxt5cT7iqaRMQX2XgtW09Nu9R"
|
||||||
"bUIVS7n2mw3iqZG0xnG3iv1oL9gwNXMLlf+gLmsqU3788jaEZ9IhZ8VdgHAoHm6UWM"
|
"bUIVS7n2mw3iqZG0xnG3iv1oL9gwNXMLlf+gLmsqU3788jaEZ9IhZ8VdgHAoHm6UWM"
|
||||||
"7b2uADmhirI6dRZUVO+/iMGUvDxa66OI4hDV055pbwQhtxupUatThyDzIg== "
|
"7b2uADmhirI6dRZUVO+/iMGUvDxa66OI4hDV055pbwQhtxupUatThyDzIg==\n";
|
||||||
"aris@aris-air\n";
|
|
||||||
|
|
||||||
static const char torture_dsa_testkey_cert[] =
|
static const char torture_dsa_testkey_cert[] =
|
||||||
"ssh-dss-cert-v01@openssh.com AAAAHHNzaC1kc3MtY2VydC12MDFAb3BlbnNza"
|
"ssh-dss-cert-v01@openssh.com AAAAHHNzaC1kc3MtY2VydC12MDFAb3BlbnNza"
|
||||||
|
@@ -31,6 +31,8 @@ static int setup_rsa_key(void **state)
|
|||||||
torture_get_testkey(SSH_KEYTYPE_RSA, 0, 1));
|
torture_get_testkey(SSH_KEYTYPE_RSA, 0, 1));
|
||||||
torture_write_file(LIBSSH_RSA_TESTKEY ".pub",
|
torture_write_file(LIBSSH_RSA_TESTKEY ".pub",
|
||||||
torture_get_testkey_pub(SSH_KEYTYPE_RSA, 0));
|
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_write_file(LIBSSH_RSA_TESTKEY "-cert.pub",
|
||||||
torture_get_testkey_pub(SSH_KEYTYPE_RSA_CERT01, 0));
|
torture_get_testkey_pub(SSH_KEYTYPE_RSA_CERT01, 0));
|
||||||
|
|
||||||
@@ -48,6 +50,21 @@ static int teardown(void **state) {
|
|||||||
return 0;
|
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)
|
static void torture_pki_rsa_import_privkey_base64_NULL_key(void **state)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
@@ -546,6 +563,9 @@ static void torture_pki_rsa_import_privkey_base64_passphrase(void **state)
|
|||||||
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_pki_rsa_import_pubkey_file,
|
||||||
|
setup_rsa_key,
|
||||||
|
teardown),
|
||||||
cmocka_unit_test_setup_teardown(torture_pki_rsa_import_privkey_base64_NULL_key,
|
cmocka_unit_test_setup_teardown(torture_pki_rsa_import_privkey_base64_NULL_key,
|
||||||
setup_rsa_key,
|
setup_rsa_key,
|
||||||
teardown),
|
teardown),
|
||||||
|
Reference in New Issue
Block a user