logo

utils-std

Collection of commonly available Unix tools
commit: 5d9d42efaa85c24ff01921218021b5bd91d4a9ae
parent 5550d60f8c14f3bd48555777f48f288efbf1dbbd
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Tue, 23 Apr 2024 13:06:50 +0200

cmd/test.1: Add TOCTOU note

Diffstat:

Mcmd/test.17+++++++
Mcmd/test.c4++++
2 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/cmd/test.1 b/cmd/test.1 @@ -57,6 +57,13 @@ All operators and flags are separate arguments to the .Nm utility. .Pp +When checking +.Ar file , +one should consider TOCTOU race-conditions. +Avoiding the issue altogether with directly using +.Ar file +instead is strongly recommended. +.Pp The following primaries are used to construct expression: .Bl -tag -width Ar .It Fl b Ar file diff --git a/cmd/test.c b/cmd/test.c @@ -366,12 +366,16 @@ filstat(char *nm, enum token mode) switch(mode) { case FILRD: + /* flawfinder: ignore, not for using later */ return (access(nm, R_OK) == 0); case FILWR: + /* flawfinder: ignore, not for using later */ return (access(nm, W_OK) == 0); case FILEX: + /* flawfinder: ignore, not for using later */ return (access(nm, X_OK) == 0); case FILEXIST: + /* flawfinder: ignore, not for using later */ return (access(nm, F_OK) == 0); case FILREG: return S_ISREG(s.st_mode);