Re: [PATCH v3 ima-evm-utils 1/3] Reset 'errno' after failure to open or access a file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 5/20/22 12:11, Mimi Zohar wrote:
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@xxxxxxxxxxxxx>
---
  src/evmctl.c    | 16 ++++++++++++++--
  src/libimaevm.c |  4 ++++
  src/utils.c     |  5 ++++-
  3 files changed, 22 insertions(+), 3 deletions(-)


diff --git a/src/utils.c b/src/utils.c
index 294dac554392..1026d44776da 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -11,6 +11,7 @@
  #include <string.h>
  #include <sys/stat.h>
  #include <unistd.h>
+#include <errno.h>
#include "utils.h" @@ -26,8 +27,10 @@ static int file_exist(const char *path)
  {
  	struct stat st;
- if (!access(path, R_OK) && !stat(path, &st) && S_ISREG(st.st_mode))
+	if (!access(path, R_OK) && !stat(path, &st) && S_ISREG(st.st_mode)) {
+		errno = 0;

!access and !stat are actually successes, so resetting errno in this particular place should not be necessary.

  		return 1;
+	}
return 0;
  }



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux Kernel]     [Linux Kernel Hardening]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux