aboutsummaryrefslogtreecommitdiff
path: root/maintainer-scripts
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2022-07-28 17:21:29 -0400
committerDavid Malcolm <dmalcolm@redhat.com>2022-07-28 17:21:29 -0400
commit872693eebb6b88f4b6a2767727a9565d05172768 (patch)
tree902dcc07d5c83ef0124204e7cc5795e684fbaffb /maintainer-scripts
parent9c60338061bf3679f925be12273dc723b3913b75 (diff)
downloadgcc-872693eebb6b88f4b6a2767727a9565d05172768.zip
gcc-872693eebb6b88f4b6a2767727a9565d05172768.tar.gz
gcc-872693eebb6b88f4b6a2767727a9565d05172768.tar.bz2
analyzer: new warning: -Wanalyzer-putenv-of-auto-var [PR105893]
This patch implements a new -fanalyzer warning: -Wanalyzer-putenv-of-auto-var which complains about stack pointers passed to putenv(3) calls, as per SEI CERT C Coding Standard rule POS34-C ("Do not call putenv() with a pointer to an automatic variable as the argument"). For example, given: #include <stdio.h> #include <stdlib.h> void test_arr (void) { char arr[] = "NAME=VALUE"; putenv (arr); } it emits: demo.c: In function ‘test_arr’: demo.c:7:3: warning: ‘putenv’ on a pointer to automatic variable ‘arr’ [POS34-C] [-Wanalyzer-putenv-of-auto-var] 7 | putenv (arr); | ^~~~~~~~~~~~ ‘test_arr’: event 1 | | 7 | putenv (arr); | | ^~~~~~~~~~~~ | | | | | (1) ‘putenv’ on a pointer to automatic variable ‘arr’ | demo.c:6:8: note: ‘arr’ declared on stack here 6 | char arr[] = "NAME=VALUE"; | ^~~ demo.c:7:3: note: perhaps use ‘setenv’ rather than ‘putenv’ 7 | putenv (arr); | ^~~~~~~~~~~~ gcc/analyzer/ChangeLog: PR analyzer/105893 * analyzer.opt (Wanalyzer-putenv-of-auto-var): New. * region-model-impl-calls.cc (class putenv_of_auto_var): New. (region_model::impl_call_putenv): New. * region-model.cc (region_model::on_call_pre): Handle putenv. * region-model.h (region_model::impl_call_putenv): New decl. gcc/ChangeLog: PR analyzer/105893 * doc/invoke.texi: Add -Wanalyzer-putenv-of-auto-var. gcc/testsuite/ChangeLog: PR analyzer/105893 * gcc.dg/analyzer/putenv-1.c: New test. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diffstat (limited to 'maintainer-scripts')
0 files changed, 0 insertions, 0 deletions