aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMateusz Kusiak <mateusz.kusiak@intel.com>2024-02-20 11:56:09 +0100
committerMariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>2024-02-23 12:43:43 +0100
commitb7d7837128e90c8b496ebc3d88eda1a8ff477392 (patch)
treec5ad6008284ced014a5c72cc1f4d2e50d7229dae
parent38cb95dd28fa790ae6d90b169f1fd2b1d09a02f2 (diff)
downloadmdadm-b7d7837128e90c8b496ebc3d88eda1a8ff477392.tar.gz
Monitor: open file before check in check_one_sharer()
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> Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
-rw-r--r--Monitor.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/Monitor.c b/Monitor.c
index 824a69fc..7cee95d4 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);