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:
32
src/pki.c
32
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);
|
||||
|
Reference in New Issue
Block a user