]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-tests: Fix CID 1373387 - Time of check time of use (TOCTOU)
authorMartin Schwenke <martin@meltin.net>
Fri, 7 Oct 2016 03:30:19 +0000 (14:30 +1100)
committerAnoop C S <anoopcs@samba.org>
Mon, 28 Jul 2025 05:45:28 +0000 (05:45 +0000)
Coverity doesn't like the fopen(3) after stat(2).  This is test code
that runs in a simple test environment, so this doesn't really matter.

However, reorder the code to put the stat(2) after the fopen(3).  This
means that the test still does all the same checks and it should now
make Coverity happy.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Anoop C S <anoopcs@samba.org>
ctdb/tests/src/pidfile_test.c

index 592fc2b934a2005df7ec81e576876f1b958945c9..5229ac2c02c42f2fea12310188ce489177405be3 100644 (file)
@@ -38,10 +38,6 @@ static void test1(const char *pidfile)
        assert(ret == 0);
        assert(pid_ctx != NULL);
 
-       ret = stat(pidfile, &st);
-       assert(ret == 0);
-       assert(S_ISREG(st.st_mode));
-
        fp = fopen(pidfile, "r");
        assert(fp != NULL);
        ret = fscanf(fp, "%d", &pid);
@@ -49,6 +45,10 @@ static void test1(const char *pidfile)
        assert(pid == getpid());
        fclose(fp);
 
+       ret = stat(pidfile, &st);
+       assert(ret == 0);
+       assert(S_ISREG(st.st_mode));
+
        TALLOC_FREE(pid_ctx);
 
        ret = stat(pidfile, &st);