diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst index 2f5336ae6a67f4..4b0b53ca8da2bc 100644 --- a/clang/docs/analyzer/checkers.rst +++ b/clang/docs/analyzer/checkers.rst @@ -2268,6 +2268,25 @@ Finds calls to the ``putenv`` function which pass a pointer to an automatic vari return putenv(env); // putenv function should not be called with auto variables } +Limitations: + + - Technically, one can pass automatic variables to ``putenv``, + but one needs to ensure that the given environment key stays + alive until it's removed or overwritten. + Since the analyzer cannot keep track of which envvars get overwritten + and when, it needs to be slightly more aggressive and warn for such + cases too, leading in some cases to false-positive reports like this: + + .. code-block:: c + + void baz() { + char env[] = "NAME=value"; + putenv(env); // false-positive warning: putenv function should not be called... + // More code... + putenv((char *)"NAME=anothervalue"); + // This putenv call overwrites the previous entry, thus that can no longer dangle. + } // 'env' array becomes dead only here. + alpha.security.cert.env ^^^^^^^^^^^^^^^^^^^^^^^