diff options
author | Oliver Stöneberg <oliverst@online.de> | 2011-04-11 11:06:32 +0200 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2011-04-11 11:06:32 +0200 |
commit | 46475dfa2f246c4a831289bc7625c896eafa6458 (patch) | |
tree | 30a21c5d4194770b60b751776549c4d3c271874f /src/keyfiles.c | |
parent | 7150cabafa6265ebe7b6d7705b3260462c4810b2 (diff) | |
download | libssh-46475dfa2f246c4a831289bc7625c896eafa6458.tar.gz libssh-46475dfa2f246c4a831289bc7625c896eafa6458.tar.xz libssh-46475dfa2f246c4a831289bc7625c896eafa6458.zip |
keys: Fixed issues reported by cppcheck.
Diffstat (limited to 'src/keyfiles.c')
-rw-r--r-- | src/keyfiles.c | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/src/keyfiles.c b/src/keyfiles.c index e7351f07..366baade 100644 --- a/src/keyfiles.c +++ b/src/keyfiles.c @@ -720,8 +720,6 @@ ssh_private_key privatekey_from_file(ssh_session session, const char *filename, (void *) passphrase, NULL); } - fclose(file); - if (!valid) { ssh_set_error(session, SSH_FATAL, "Parsing private key %s", filename); #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); } - fclose(file); if (dsa == NULL) { ssh_set_error(session, SSH_FATAL, "Parsing private key %s: %s", filename, ERR_error_string(ERR_get_error(), NULL)); #endif + fclose(file); return NULL; } break; @@ -760,8 +758,6 @@ ssh_private_key privatekey_from_file(ssh_session session, const char *filename, (void *) passphrase, NULL); } - fclose(file); - if (!valid) { ssh_set_error(session,SSH_FATAL, "Parsing private key %s", filename); #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); } - fclose(file); - if (rsa == NULL) { ssh_set_error(session, SSH_FATAL, "Parsing private key %s: %s", filename, ERR_error_string(ERR_get_error(),NULL)); #endif + fclose(file); return NULL; } break; @@ -791,6 +786,8 @@ ssh_private_key privatekey_from_file(ssh_session session, const char *filename, return NULL; } /* switch */ + fclose(file); + privkey = malloc(sizeof(struct ssh_private_key_struct)); if (privkey == NULL) { #ifdef HAVE_LIBGCRYPT @@ -850,20 +847,19 @@ ssh_private_key _privatekey_from_file(void *session, const char *filename, #ifdef HAVE_LIBGCRYPT valid = read_dsa_privatekey(file, &dsa, NULL, NULL, NULL); - fclose(file); - if (!valid) { ssh_set_error(session, SSH_FATAL, "Parsing private key %s", filename); #elif defined HAVE_LIBCRYPTO dsa = PEM_read_DSAPrivateKey(file, NULL, NULL, NULL); - fclose(file); - if (dsa == NULL) { ssh_set_error(session, SSH_FATAL, "Parsing private key %s: %s", filename, ERR_error_string(ERR_get_error(), NULL)); +#else + { #endif + fclose(file); return NULL; } break; @@ -871,28 +867,30 @@ ssh_private_key _privatekey_from_file(void *session, const char *filename, #ifdef HAVE_LIBGCRYPT valid = read_rsa_privatekey(file, &rsa, NULL, NULL, NULL); - fclose(file); - if (!valid) { ssh_set_error(session, SSH_FATAL, "Parsing private key %s", filename); #elif defined HAVE_LIBCRYPTO rsa = PEM_read_RSAPrivateKey(file, NULL, NULL, NULL); - fclose(file); - if (rsa == NULL) { ssh_set_error(session, SSH_FATAL, "Parsing private key %s: %s", filename, ERR_error_string(ERR_get_error(), NULL)); +#else + { #endif + fclose(file); return NULL; } break; default: + fclose(file); ssh_set_error(session, SSH_FATAL, "Invalid private key type %d", type); return NULL; } + fclose(file); + privkey = malloc(sizeof(struct ssh_private_key_struct)); if (privkey == NULL) { #ifdef HAVE_LIBGCRYPT |