Skip to content

Commit 8cc2de6

Browse files
committed
[analyzer][docs] Fix the incorrect structure of the checker docs
The alpha.security.cert section came right after alpha.security, making it look like checkers like alpha.security.MmapWriteExec belonged to that package. Differential Revision: https://reviews.llvm.org/D113397
1 parent 9d9019c commit 8cc2de6

File tree

1 file changed

+89
-84
lines changed

1 file changed

+89
-84
lines changed

clang/docs/analyzer/checkers.rst

Lines changed: 89 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -2064,90 +2064,6 @@ Warns against using one vs. many plural pattern in code when generating localize
20642064
alpha.security
20652065
^^^^^^^^^^^^^^
20662066
2067-
2068-
alpha.security.cert
2069-
^^^^^^^^^^^^^^^^^^^
2070-
2071-
SEI CERT checkers which tries to find errors based on their `C coding rules <https://wiki.sei.cmu.edu/confluence/display/c/2+Rules>`_.
2072-
2073-
.. _alpha-security-cert-pos-checkers:
2074-
2075-
alpha.security.cert.pos
2076-
^^^^^^^^^^^^^^^^^^^^^^^
2077-
2078-
SEI CERT checkers of `POSIX C coding rules <https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152405>`__.
2079-
2080-
.. _alpha-security-cert-pos-34c:
2081-
2082-
alpha.security.cert.pos.34c
2083-
"""""""""""""""""""""""""""
2084-
Finds calls to the ``putenv`` function which pass a pointer to an automatic variable as the argument.
2085-
2086-
.. code-block:: c
2087-
2088-
int func(const char *var) {
2089-
char env[1024];
2090-
int retval = snprintf(env, sizeof(env),"TEST=%s", var);
2091-
if (retval < 0 || (size_t)retval >= sizeof(env)) {
2092-
/* Handle error */
2093-
}
2094-
2095-
return putenv(env); // putenv function should not be called with auto variables
2096-
}
2097-
2098-
alpha.security.cert.env
2099-
^^^^^^^^^^^^^^^^^^^^^^^
2100-
2101-
SEI CERT checkers of `POSIX C coding rules <https://wiki.sei.cmu.edu/confluence/x/JdcxBQ>`__.
2102-
2103-
.. _alpha-security-cert-env-InvalidPtr:
2104-
2105-
alpha.security.cert.env.InvalidPtr
2106-
""""""""""""""""""""""""""""""""""
2107-
2108-
Corresponds to SEI CERT Rules ENV31-C and ENV34-C.
2109-
2110-
ENV31-C:
2111-
Rule is about the possible problem with `main` function's third argument, environment pointer,
2112-
"envp". When enviornment array is modified using some modification function
2113-
such as putenv, setenv or others, It may happen that memory is reallocated,
2114-
however "envp" is not updated to reflect the changes and points to old memory
2115-
region.
2116-
2117-
ENV34-C:
2118-
Some functions return a pointer to a statically allocated buffer.
2119-
Consequently, subsequent call of these functions will invalidate previous
2120-
pointer. These functions include: getenv, localeconv, asctime, setlocale, strerror
2121-
2122-
.. code-block:: c
2123-
2124-
int main(int argc, const char *argv[], const char *envp[]) {
2125-
if (setenv("MY_NEW_VAR", "new_value", 1) != 0) {
2126-
// setenv call may invalidate 'envp'
2127-
/* Handle error */
2128-
}
2129-
if (envp != NULL) {
2130-
for (size_t i = 0; envp[i] != NULL; ++i) {
2131-
puts(envp[i]);
2132-
// envp may no longer point to the current environment
2133-
// this program has unanticipated behavior, since envp
2134-
// does not reflect changes made by setenv function.
2135-
}
2136-
}
2137-
return 0;
2138-
}
2139-
2140-
void previous_call_invalidation() {
2141-
char *p, *pp;
2142-
2143-
p = getenv("VAR");
2144-
pp = getenv("VAR2");
2145-
// subsequent call to 'getenv' invalidated previous one
2146-
2147-
*p;
2148-
// dereferencing invalid pointer
2149-
}
2150-
21512067
.. _alpha-security-ArrayBound:
21522068
21532069
alpha.security.ArrayBound (C)
@@ -2299,6 +2215,95 @@ Check for an out-of-bound pointer being returned to callers.
22992215
return x; // warn: undefined or garbage returned
23002216
}
23012217
2218+
2219+
alpha.security.cert
2220+
^^^^^^^^^^^^^^^^^^^
2221+
2222+
SEI CERT checkers which tries to find errors based on their `C coding rules <https://wiki.sei.cmu.edu/confluence/display/c/2+Rules>`_.
2223+
2224+
.. _alpha-security-cert-pos-checkers:
2225+
2226+
alpha.security.cert.pos
2227+
^^^^^^^^^^^^^^^^^^^^^^^
2228+
2229+
SEI CERT checkers of `POSIX C coding rules <https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152405>`_.
2230+
2231+
.. _alpha-security-cert-pos-34c:
2232+
2233+
alpha.security.cert.pos.34c
2234+
"""""""""""""""""""""""""""
2235+
Finds calls to the ``putenv`` function which pass a pointer to an automatic variable as the argument.
2236+
2237+
.. code-block:: c
2238+
2239+
int func(const char *var) {
2240+
char env[1024];
2241+
int retval = snprintf(env, sizeof(env),"TEST=%s", var);
2242+
if (retval < 0 || (size_t)retval >= sizeof(env)) {
2243+
/* Handle error */
2244+
}
2245+
2246+
return putenv(env); // putenv function should not be called with auto variables
2247+
}
2248+
2249+
alpha.security.cert.env
2250+
^^^^^^^^^^^^^^^^^^^^^^^
2251+
2252+
SEI CERT checkers of `Environment C coding rules <https://wiki.sei.cmu.edu/confluence/x/JdcxBQ>`_.
2253+
2254+
.. _alpha-security-cert-env-InvalidPtr:
2255+
2256+
alpha.security.cert.env.InvalidPtr
2257+
""""""""""""""""""""""""""""""""""
2258+
2259+
Corresponds to SEI CERT Rules ENV31-C and ENV34-C.
2260+
2261+
ENV31-C:
2262+
Rule is about the possible problem with `main` function's third argument, environment pointer,
2263+
"envp". When enviornment array is modified using some modification function
2264+
such as putenv, setenv or others, It may happen that memory is reallocated,
2265+
however "envp" is not updated to reflect the changes and points to old memory
2266+
region.
2267+
2268+
ENV34-C:
2269+
Some functions return a pointer to a statically allocated buffer.
2270+
Consequently, subsequent call of these functions will invalidate previous
2271+
pointer. These functions include: getenv, localeconv, asctime, setlocale, strerror
2272+
2273+
.. code-block:: c
2274+
2275+
int main(int argc, const char *argv[], const char *envp[]) {
2276+
if (setenv("MY_NEW_VAR", "new_value", 1) != 0) {
2277+
// setenv call may invalidate 'envp'
2278+
/* Handle error */
2279+
}
2280+
if (envp != NULL) {
2281+
for (size_t i = 0; envp[i] != NULL; ++i) {
2282+
puts(envp[i]);
2283+
// envp may no longer point to the current environment
2284+
// this program has unanticipated behavior, since envp
2285+
// does not reflect changes made by setenv function.
2286+
}
2287+
}
2288+
return 0;
2289+
}
2290+
2291+
void previous_call_invalidation() {
2292+
char *p, *pp;
2293+
2294+
p = getenv("VAR");
2295+
pp = getenv("VAR2");
2296+
// subsequent call to 'getenv' invalidated previous one
2297+
2298+
*p;
2299+
// dereferencing invalid pointer
2300+
}
2301+
2302+
alpha.security.taint
2303+
^^^^^^^^^^^^^^^^^^^^
2304+
2305+
Checkers implementing `taint analysis <https://en.wikipedia.org/wiki/Taint_checking>`_.
2306+
23022307
.. _alpha-security-taint-TaintPropagation:
23032308
23042309
alpha.security.taint.TaintPropagation (C, C++)

0 commit comments

Comments
 (0)