putenv is given a local array, which the environment keeps using after the function returns
What it finds
char buf[64]; snprintf(buf, ...); putenv(buf);: putenv does not copy the string but makes it part of the environment, so when the function returns the environment points into stack memory that later calls overwrite. setenv copies.
From the rule's source, putenv_local_buffer.rs.
#include <stdio.h>#include <stdlib.h> static char kept[64]; void set(const char *value){ char buf[64]; snprintf(buf, sizeof(buf), "HOME=%s", value); putenv(buf);tx0 reports: the environment keeps pointing into the local array buf snprintf(kept, sizeof(kept), "HOME=%s", value); putenv(kept);} 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:
[rules]
"tx0/c:putenv-local-buffer" = "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:putenv-local-buffer] reason="..."tx0 explain tx0/c:putenv-local-buffer shows the same in the terminal. Found a false positive? Report it.