1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-08-08 19:02:06 +03:00

pki: Use fstat() after opening the file.

This commit is contained in:
Andreas Schneider
2013-06-13 11:04:59 +02:00
parent a03d8f49fb
commit 09663692dd

View File

@@ -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);