]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Monitor: open file before check in check_one_sharer()
authorMateusz Kusiak <mateusz.kusiak@intel.com>
Tue, 20 Feb 2024 10:56:09 +0000 (11:56 +0100)
committerMariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Fri, 23 Feb 2024 11:43:43 +0000 (12:43 +0100)
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>
Monitor.c

index 824a69fc6b79e37aa19de7ccad0701089f2b66c9..7cee95d4487ab89bb356c50e74712566079c95c6 100644 (file)
--- 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);