@@ -2064,90 +2064,6 @@ Warns against using one vs. many plural pattern in code when generating localize
2064
2064
alpha.security
2065
2065
^^^^^^^^^^^^^^
2066
2066
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
-
2151
2067
.. _alpha-security-ArrayBound :
2152
2068
2153
2069
alpha.security .ArrayBound (C)
@@ -2299,6 +2215,95 @@ Check for an out-of-bound pointer being returned to callers.
2299
2215
return x; // warn: undefined or garbage returned
2300
2216
}
2301
2217
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
+
2302
2307
.. _alpha-security-taint-TaintPropagation :
2303
2308
2304
2309
alpha.security .taint .TaintPropagation (C, C++)
0 commit comments