summaryrefslogtreecommitdiffstats
path: root/src/pki.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pki.c')
-rw-r--r--src/pki.c32
1 files changed, 16 insertions, 16 deletions
diff --git a/src/pki.c b/src/pki.c
index 87d7e76..ff03138 100644
--- a/src/pki.c
+++ b/src/pki.c
@@ -421,7 +421,14 @@ int ssh_pki_import_privkey_file(const char *filename,
return SSH_ERROR;
}
- rc = stat(filename, &sb);
+ file = fopen(filename, "rb");
+ if (file == NULL) {
+ ssh_pki_log("Error opening %s: %s",
+ filename, strerror(errno));
+ return SSH_EOF;
+ }
+
+ rc = fstat(fileno(file), &sb);
if (rc < 0) {
ssh_pki_log("Error getting stat of %s: %s",
filename, strerror(errno));
@@ -434,13 +441,6 @@ int ssh_pki_import_privkey_file(const char *filename,
return SSH_ERROR;
}
- file = fopen(filename, "rb");
- if (file == NULL) {
- ssh_pki_log("Error opening %s: %s",
- filename, strerror(errno));
- return SSH_EOF;
- }
-
key_buf = malloc(sb.st_size + 1);
if (key_buf == NULL) {
fclose(file);
@@ -804,7 +804,14 @@ int ssh_pki_import_pubkey_file(const char *filename, ssh_key *pkey)
return SSH_ERROR;
}
- rc = stat(filename, &sb);
+ file = fopen(filename, "r");
+ if (file == NULL) {
+ ssh_pki_log("Error opening %s: %s",
+ filename, strerror(errno));
+ return SSH_EOF;
+ }
+
+ rc = fstat(fileno(file), &sb);
if (rc < 0) {
ssh_pki_log("Error gettint stat of %s: %s",
filename, strerror(errno));
@@ -820,13 +827,6 @@ int ssh_pki_import_pubkey_file(const char *filename, ssh_key *pkey)
return SSH_ERROR;
}
- file = fopen(filename, "r");
- if (file == NULL) {
- ssh_pki_log("Error opening %s: %s",
- filename, strerror(errno));
- return SSH_EOF;
- }
-
key_buf = malloc(sb.st_size + 1);
if (key_buf == NULL) {
fclose(file);