mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-09 09:54:25 +09:00
keys: Fixed issues reported by cppcheck.
This commit is contained in:
committed by
Andreas Schneider
parent
7150cabafa
commit
46475dfa2f
@@ -720,8 +720,6 @@ ssh_private_key privatekey_from_file(ssh_session session, const char *filename,
|
|||||||
(void *) passphrase, NULL);
|
(void *) passphrase, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(file);
|
|
||||||
|
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
ssh_set_error(session, SSH_FATAL, "Parsing private key %s", filename);
|
ssh_set_error(session, SSH_FATAL, "Parsing private key %s", filename);
|
||||||
#elif defined HAVE_LIBCRYPTO
|
#elif defined HAVE_LIBCRYPTO
|
||||||
@@ -735,12 +733,12 @@ ssh_private_key privatekey_from_file(ssh_session session, const char *filename,
|
|||||||
dsa = PEM_read_DSAPrivateKey(file, NULL, NULL, (void *) passphrase);
|
dsa = PEM_read_DSAPrivateKey(file, NULL, NULL, (void *) passphrase);
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(file);
|
|
||||||
if (dsa == NULL) {
|
if (dsa == NULL) {
|
||||||
ssh_set_error(session, SSH_FATAL,
|
ssh_set_error(session, SSH_FATAL,
|
||||||
"Parsing private key %s: %s",
|
"Parsing private key %s: %s",
|
||||||
filename, ERR_error_string(ERR_get_error(), NULL));
|
filename, ERR_error_string(ERR_get_error(), NULL));
|
||||||
#endif
|
#endif
|
||||||
|
fclose(file);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -760,8 +758,6 @@ ssh_private_key privatekey_from_file(ssh_session session, const char *filename,
|
|||||||
(void *) passphrase, NULL);
|
(void *) passphrase, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(file);
|
|
||||||
|
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
ssh_set_error(session,SSH_FATAL, "Parsing private key %s", filename);
|
ssh_set_error(session,SSH_FATAL, "Parsing private key %s", filename);
|
||||||
#elif defined HAVE_LIBCRYPTO
|
#elif defined HAVE_LIBCRYPTO
|
||||||
@@ -775,13 +771,12 @@ ssh_private_key privatekey_from_file(ssh_session session, const char *filename,
|
|||||||
rsa = PEM_read_RSAPrivateKey(file, NULL, NULL, (void *) passphrase);
|
rsa = PEM_read_RSAPrivateKey(file, NULL, NULL, (void *) passphrase);
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(file);
|
|
||||||
|
|
||||||
if (rsa == NULL) {
|
if (rsa == NULL) {
|
||||||
ssh_set_error(session, SSH_FATAL,
|
ssh_set_error(session, SSH_FATAL,
|
||||||
"Parsing private key %s: %s",
|
"Parsing private key %s: %s",
|
||||||
filename, ERR_error_string(ERR_get_error(),NULL));
|
filename, ERR_error_string(ERR_get_error(),NULL));
|
||||||
#endif
|
#endif
|
||||||
|
fclose(file);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -791,6 +786,8 @@ ssh_private_key privatekey_from_file(ssh_session session, const char *filename,
|
|||||||
return NULL;
|
return NULL;
|
||||||
} /* switch */
|
} /* switch */
|
||||||
|
|
||||||
|
fclose(file);
|
||||||
|
|
||||||
privkey = malloc(sizeof(struct ssh_private_key_struct));
|
privkey = malloc(sizeof(struct ssh_private_key_struct));
|
||||||
if (privkey == NULL) {
|
if (privkey == NULL) {
|
||||||
#ifdef HAVE_LIBGCRYPT
|
#ifdef HAVE_LIBGCRYPT
|
||||||
@@ -850,20 +847,19 @@ ssh_private_key _privatekey_from_file(void *session, const char *filename,
|
|||||||
#ifdef HAVE_LIBGCRYPT
|
#ifdef HAVE_LIBGCRYPT
|
||||||
valid = read_dsa_privatekey(file, &dsa, NULL, NULL, NULL);
|
valid = read_dsa_privatekey(file, &dsa, NULL, NULL, NULL);
|
||||||
|
|
||||||
fclose(file);
|
|
||||||
|
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
ssh_set_error(session, SSH_FATAL, "Parsing private key %s", filename);
|
ssh_set_error(session, SSH_FATAL, "Parsing private key %s", filename);
|
||||||
#elif defined HAVE_LIBCRYPTO
|
#elif defined HAVE_LIBCRYPTO
|
||||||
dsa = PEM_read_DSAPrivateKey(file, NULL, NULL, NULL);
|
dsa = PEM_read_DSAPrivateKey(file, NULL, NULL, NULL);
|
||||||
|
|
||||||
fclose(file);
|
|
||||||
|
|
||||||
if (dsa == NULL) {
|
if (dsa == NULL) {
|
||||||
ssh_set_error(session, SSH_FATAL,
|
ssh_set_error(session, SSH_FATAL,
|
||||||
"Parsing private key %s: %s",
|
"Parsing private key %s: %s",
|
||||||
filename, ERR_error_string(ERR_get_error(), NULL));
|
filename, ERR_error_string(ERR_get_error(), NULL));
|
||||||
|
#else
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
fclose(file);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -871,28 +867,30 @@ ssh_private_key _privatekey_from_file(void *session, const char *filename,
|
|||||||
#ifdef HAVE_LIBGCRYPT
|
#ifdef HAVE_LIBGCRYPT
|
||||||
valid = read_rsa_privatekey(file, &rsa, NULL, NULL, NULL);
|
valid = read_rsa_privatekey(file, &rsa, NULL, NULL, NULL);
|
||||||
|
|
||||||
fclose(file);
|
|
||||||
|
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
ssh_set_error(session, SSH_FATAL, "Parsing private key %s", filename);
|
ssh_set_error(session, SSH_FATAL, "Parsing private key %s", filename);
|
||||||
#elif defined HAVE_LIBCRYPTO
|
#elif defined HAVE_LIBCRYPTO
|
||||||
rsa = PEM_read_RSAPrivateKey(file, NULL, NULL, NULL);
|
rsa = PEM_read_RSAPrivateKey(file, NULL, NULL, NULL);
|
||||||
|
|
||||||
fclose(file);
|
|
||||||
|
|
||||||
if (rsa == NULL) {
|
if (rsa == NULL) {
|
||||||
ssh_set_error(session, SSH_FATAL,
|
ssh_set_error(session, SSH_FATAL,
|
||||||
"Parsing private key %s: %s",
|
"Parsing private key %s: %s",
|
||||||
filename, ERR_error_string(ERR_get_error(), NULL));
|
filename, ERR_error_string(ERR_get_error(), NULL));
|
||||||
|
#else
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
fclose(file);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
fclose(file);
|
||||||
ssh_set_error(session, SSH_FATAL, "Invalid private key type %d", type);
|
ssh_set_error(session, SSH_FATAL, "Invalid private key type %d", type);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fclose(file);
|
||||||
|
|
||||||
privkey = malloc(sizeof(struct ssh_private_key_struct));
|
privkey = malloc(sizeof(struct ssh_private_key_struct));
|
||||||
if (privkey == NULL) {
|
if (privkey == NULL) {
|
||||||
#ifdef HAVE_LIBGCRYPT
|
#ifdef HAVE_LIBGCRYPT
|
||||||
|
|||||||
@@ -597,7 +597,9 @@ error:
|
|||||||
ssh_string_free(n);
|
ssh_string_free(n);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
|
#if defined(HAVE_LIBGCRYPT) || defined(HAVE_LIBCRYPTO)
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_LIBGCRYPT
|
#ifdef HAVE_LIBGCRYPT
|
||||||
static int rsa_public_to_string(gcry_sexp_t key, ssh_buffer buffer) {
|
static int rsa_public_to_string(gcry_sexp_t key, ssh_buffer buffer) {
|
||||||
@@ -665,7 +667,9 @@ error:
|
|||||||
ssh_string_free(n);
|
ssh_string_free(n);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
|
#if defined(HAVE_LIBGCRYPT) || defined(HAVE_LIBCRYPTO)
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Convert a public_key object into a a SSH string.
|
* @brief Convert a public_key object into a a SSH string.
|
||||||
|
|||||||
Reference in New Issue
Block a user