diff mbox series

[3/6] Monitor: open file before check in check_one_sharer()

Message ID 20240220105612.31058-4-mateusz.kusiak@intel.com (mailing list archive)
State Accepted
Headers show
Series SAST fixes | expand

Commit Message

Mateusz Kusiak Feb. 20, 2024, 10:56 a.m. UTC
Open file before performing checks in check_one_sharer() to avoid
file tampering.
Remove redundant access check.

Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com>
---
 Monitor.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/Monitor.c b/Monitor.c
index 824a69fc6b79..7cee95d4487a 100644
--- a/Monitor.c
+++ b/Monitor.c
@@ -451,20 +451,17 @@  static int check_one_sharer(int scan)
 		return 2;
 	}
 
-	if (access(AUTOREBUILD_PID_PATH, F_OK) != 0)
-		return 0;
-
-	if (!is_file(AUTOREBUILD_PID_PATH)) {
-		pr_err("%s is not a regular file.\n", AUTOREBUILD_PID_PATH);
-		return 2;
-	}
-
 	fp = fopen(AUTOREBUILD_PID_PATH, "r");
 	if (!fp) {
 		pr_err("Cannot open %s file.\n", AUTOREBUILD_PID_PATH);
 		return 2;
 	}
 
+	if (!is_file(AUTOREBUILD_PID_PATH)) {
+		pr_err("%s is not a regular file.\n", AUTOREBUILD_PID_PATH);
+		return 2;
+	}
+
 	if (fscanf(fp, "%d", &pid) != 1) {
 		pr_err("Cannot read pid from %s file.\n", AUTOREBUILD_PID_PATH);
 		fclose(fp);