A file is checked with access and opened by name afterwards, so it may have changed in between

tx0/cpp:check-then-openrecommendedwarningsecurity/filesdepth fastsecurity, cwe-367

What it finds

if (access(path, W_OK) == 0) f = fopen(path, "w");: between the check and the open, another process can replace the file with a link to one the program should not touch. Opening the file and checking what was opened, with the program's own permissions, leaves no gap.

The open must come later in the same function with the same path, written the same way and without side effects.

From the rule's source, check_then_open.rs.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/cpp:check-then-open" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/cpp:check-then-open] reason="..."

tx0 explain tx0/cpp:check-then-open shows the same in the terminal. Found a false positive? Report it.