A shell command is run from a string that is not a literal

tx0/cpp:shell-command-from-variablerecommendedwarningsecurity/injectiondepth fastsecurity, cwe-78

What it finds

system(cmd) and popen(cmd, "r") hand the string to the shell, which interprets spaces, quotes, ; and $(...); if any part of it comes from input, the input can run commands of its own. execv with an argument vector avoids the shell.

A literal command, and system(NULL), which only asks whether there is a shell, are left alone.

From the rule's source, shell_command_from_variable.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:shell-command-from-variable" = "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:shell-command-from-variable] reason="..."

tx0 explain tx0/cpp:shell-command-from-variable shows the same in the terminal. Found a false positive? Report it.