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

tx0/c:shell-command-from-variablerecommendedwarningsecurity, 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.

Example from the rule's tests
#include <stdio.h>#include <stdlib.h> void run(const char *cmd){  system(cmd);tx0 reports: system runs a command built at run time through the shell  system("ls -l");  FILE *p = popen(cmd, "r");tx0 reports: popen runs a command built at run time through the shell  if (system(NULL))    pclose(p);}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

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/c: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/c:shell-command-from-variable] reason="..."

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