From 09663692dd317c658e52c68c2096fdbae3a733a0 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Thu, 13 Jun 2013 11:04:59 +0200 Subject: pki: Use fstat() after opening the file. --- src/pki.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'src') 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); -- cgit