aboutsummaryrefslogtreecommitdiff
path: root/src/pki.c
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2013-06-13 11:04:59 +0200
committerAndreas Schneider <asn@cryptomilk.org>2013-06-13 11:04:59 +0200
commit09663692dd317c658e52c68c2096fdbae3a733a0 (patch)
treee73e7dd64f0a4e0dcf7856ac50e0c8995b796cd6 /src/pki.c
parenta03d8f49fbba5f5dffb68404d8f05a1114d0d4b4 (diff)
downloadlibssh-09663692dd317c658e52c68c2096fdbae3a733a0.tar.gz
libssh-09663692dd317c658e52c68c2096fdbae3a733a0.tar.xz
libssh-09663692dd317c658e52c68c2096fdbae3a733a0.zip
pki: Use fstat() after opening the file.
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 87d7e765..ff03138d 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);