mirror of
https://git.code.sf.net/p/linux-ima/ima-evm-utils
synced 2025-07-16 04:00:43 +02:00
Reset 'errno' after failure to open or access a file
Not being able to open a file is not necessarily a problem. If and when it occurs, an informational or error message with the actual filename is emitted as needed. Reset 'errno' to prevent the "errno: No such file or directory (2)" generic message. Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
This commit is contained in:
@ -144,6 +144,7 @@ static int add_file_hash(const char *file, EVP_MD_CTX *ctx)
|
||||
fp = fopen(file, "r");
|
||||
if (!fp) {
|
||||
log_err("Failed to open: %s\n", file);
|
||||
errno = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -258,6 +259,7 @@ EVP_PKEY *read_pub_pkey(const char *keyfile, int x509)
|
||||
if (!fp) {
|
||||
if (imaevm_params.verbose > LOG_INFO)
|
||||
log_info("Failed to open keyfile: %s\n", keyfile);
|
||||
errno = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -735,6 +737,7 @@ static int read_keyid_from_cert(uint32_t *keyid_be, const char *certfile, int tr
|
||||
|
||||
if (!(fp = fopen(certfile, "r"))) {
|
||||
log_err("Cannot open %s: %s\n", certfile, strerror(errno));
|
||||
errno = 0;
|
||||
return -1;
|
||||
}
|
||||
if (!PEM_read_X509(fp, &x, NULL, NULL)) {
|
||||
@ -826,6 +829,7 @@ static EVP_PKEY *read_priv_pkey(const char *keyfile, const char *keypass)
|
||||
fp = fopen(keyfile, "r");
|
||||
if (!fp) {
|
||||
log_err("Failed to open keyfile: %s\n", keyfile);
|
||||
errno = 0;
|
||||
return NULL;
|
||||
}
|
||||
pkey = PEM_read_PrivateKey(fp, NULL, NULL, (void *)keypass);
|
||||
|
Reference in New Issue
Block a user