mirror of
https://git.code.sf.net/p/linux-ima/ima-evm-utils
synced 2025-04-28 06:33:36 +02:00
Revert "Reset 'errno' after failure to open or access a file"
This reverts commit acb19d1894a4a95471b8d2346cd6c3ecf3385110, based on the mailing list discussion and will be fixed in the next commit. Reviewed-by: Stefan Berger <stefanb@linux.ibm.com> Reviewed-by: Petr Vorel <pvorel@suse.cz> Link: https://lore.kernel.org/linux-integrity/20220915153659.dtykhzitxdrlpasq@altlinux.org/ Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
This commit is contained in:
parent
75fadad261
commit
0f3b9a0b2c
18
src/evmctl.c
18
src/evmctl.c
@ -182,7 +182,6 @@ static int bin2file(const char *file, const char *ext, const unsigned char *data
|
|||||||
fp = fopen(name, "w");
|
fp = fopen(name, "w");
|
||||||
if (!fp) {
|
if (!fp) {
|
||||||
log_err("Failed to open: %s\n", name);
|
log_err("Failed to open: %s\n", name);
|
||||||
errno = 0;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
err = fwrite(data, len, 1, fp);
|
err = fwrite(data, len, 1, fp);
|
||||||
@ -208,7 +207,6 @@ static unsigned char *file2bin(const char *file, const char *ext, int *size)
|
|||||||
fp = fopen(name, "r");
|
fp = fopen(name, "r");
|
||||||
if (!fp) {
|
if (!fp) {
|
||||||
log_err("Failed to open: %s\n", name);
|
log_err("Failed to open: %s\n", name);
|
||||||
errno = 0;
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (fstat(fileno(fp), &stats) == -1) {
|
if (fstat(fileno(fp), &stats) == -1) {
|
||||||
@ -315,10 +313,8 @@ static int get_uuid(struct stat *st, char *uuid)
|
|||||||
sprintf(path, "blkid -s UUID -o value /dev/block/%u:%u", major, minor);
|
sprintf(path, "blkid -s UUID -o value /dev/block/%u:%u", major, minor);
|
||||||
|
|
||||||
fp = popen(path, "r");
|
fp = popen(path, "r");
|
||||||
if (!fp) {
|
if (!fp)
|
||||||
errno = 0;
|
|
||||||
goto err;
|
goto err;
|
||||||
}
|
|
||||||
|
|
||||||
len = fread(_uuid, 1, sizeof(_uuid), fp);
|
len = fread(_uuid, 1, sizeof(_uuid), fp);
|
||||||
pclose(fp);
|
pclose(fp);
|
||||||
@ -375,7 +371,6 @@ static int calc_evm_hash(const char *file, unsigned char *hash)
|
|||||||
|
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
log_err("Failed to open: %s\n", file);
|
log_err("Failed to open: %s\n", file);
|
||||||
errno = 0;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (ioctl(fd, FS_IOC_GETVERSION, &generation)) {
|
if (ioctl(fd, FS_IOC_GETVERSION, &generation)) {
|
||||||
@ -1201,7 +1196,6 @@ static int calc_evm_hmac(const char *file, const char *keyfile, unsigned char *h
|
|||||||
|
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
log_err("Failed to open %s\n", file);
|
log_err("Failed to open %s\n", file);
|
||||||
errno = 0;
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
if (ioctl(fd, FS_IOC_GETVERSION, &generation)) {
|
if (ioctl(fd, FS_IOC_GETVERSION, &generation)) {
|
||||||
@ -1392,7 +1386,6 @@ static int ima_fix(const char *path)
|
|||||||
fd = open(path, O_RDONLY);
|
fd = open(path, O_RDONLY);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
log_errno("Failed to open file: %s", path);
|
log_errno("Failed to open file: %s", path);
|
||||||
errno = 0;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1916,10 +1909,8 @@ static int read_sysfs_pcrs(int num_banks, struct tpm_bank_info *tpm_banks)
|
|||||||
int i, result;
|
int i, result;
|
||||||
|
|
||||||
fp = fopen(pcrs, "r");
|
fp = fopen(pcrs, "r");
|
||||||
if (!fp) {
|
if (!fp)
|
||||||
fp = fopen(misc_pcrs, "r");
|
fp = fopen(misc_pcrs, "r");
|
||||||
errno = 0;
|
|
||||||
}
|
|
||||||
if (!fp)
|
if (!fp)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@ -1982,7 +1973,6 @@ static int read_file_pcrs(int num_banks, struct tpm_bank_info *tpm_banks)
|
|||||||
fp = fopen(path, "r");
|
fp = fopen(path, "r");
|
||||||
if (!fp) {
|
if (!fp) {
|
||||||
log_err("Could not open '%s'\n", path);
|
log_err("Could not open '%s'\n", path);
|
||||||
errno = 0;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2075,7 +2065,6 @@ static int ima_measurement(const char *file)
|
|||||||
fp = fopen(file, "rb");
|
fp = fopen(file, "rb");
|
||||||
if (!fp) {
|
if (!fp) {
|
||||||
log_err("Failed to open measurement file: %s\n", file);
|
log_err("Failed to open measurement file: %s\n", file);
|
||||||
errno = 0;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2321,7 +2310,6 @@ static int read_binary_bios_measurements(char *file, struct tpm_bank_info *bank)
|
|||||||
fp = fopen(file, "r");
|
fp = fopen(file, "r");
|
||||||
if (!fp) {
|
if (!fp) {
|
||||||
log_errno("Failed to open TPM 1.2 event log.\n");
|
log_errno("Failed to open TPM 1.2 event log.\n");
|
||||||
errno = 0;
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2758,8 +2746,6 @@ int main(int argc, char *argv[])
|
|||||||
unsigned long keyid;
|
unsigned long keyid;
|
||||||
char *eptr;
|
char *eptr;
|
||||||
|
|
||||||
errno = 0; /* initialize errno */
|
|
||||||
|
|
||||||
#if !(OPENSSL_VERSION_NUMBER < 0x10100000)
|
#if !(OPENSSL_VERSION_NUMBER < 0x10100000)
|
||||||
OPENSSL_init_crypto(
|
OPENSSL_init_crypto(
|
||||||
#ifndef DISABLE_OPENSSL_CONF
|
#ifndef DISABLE_OPENSSL_CONF
|
||||||
|
@ -144,7 +144,6 @@ static int add_file_hash(const char *file, EVP_MD_CTX *ctx)
|
|||||||
fp = fopen(file, "r");
|
fp = fopen(file, "r");
|
||||||
if (!fp) {
|
if (!fp) {
|
||||||
log_err("Failed to open: %s\n", file);
|
log_err("Failed to open: %s\n", file);
|
||||||
errno = 0;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -259,7 +258,6 @@ EVP_PKEY *read_pub_pkey(const char *keyfile, int x509)
|
|||||||
if (!fp) {
|
if (!fp) {
|
||||||
if (imaevm_params.verbose > LOG_INFO)
|
if (imaevm_params.verbose > LOG_INFO)
|
||||||
log_info("Failed to open keyfile: %s\n", keyfile);
|
log_info("Failed to open keyfile: %s\n", keyfile);
|
||||||
errno = 0;
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -878,7 +876,6 @@ static int read_keyid_from_cert(uint32_t *keyid_be, const char *certfile, int tr
|
|||||||
|
|
||||||
if (!(fp = fopen(certfile, "r"))) {
|
if (!(fp = fopen(certfile, "r"))) {
|
||||||
log_err("Cannot open %s: %s\n", certfile, strerror(errno));
|
log_err("Cannot open %s: %s\n", certfile, strerror(errno));
|
||||||
errno = 0;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (!PEM_read_X509(fp, &x, NULL, NULL)) {
|
if (!PEM_read_X509(fp, &x, NULL, NULL)) {
|
||||||
@ -970,7 +967,6 @@ static EVP_PKEY *read_priv_pkey(const char *keyfile, const char *keypass)
|
|||||||
fp = fopen(keyfile, "r");
|
fp = fopen(keyfile, "r");
|
||||||
if (!fp) {
|
if (!fp) {
|
||||||
log_err("Failed to open keyfile: %s\n", keyfile);
|
log_err("Failed to open keyfile: %s\n", keyfile);
|
||||||
errno = 0;
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
pkey = PEM_read_PrivateKey(fp, NULL, NULL, (void *)keypass);
|
pkey = PEM_read_PrivateKey(fp, NULL, NULL, (void *)keypass);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user