According to
https://wiki.sei.cmu.edu/confluence/display/c/POS34-C.+Do+not+call+putenv%28%29+with+a+pointer+to+an+automatic+variable+as+the+argument
cert-pos34-c check is created. The check warns if putenv function is
called with automatic storage variable as an argument.
Details
- Reviewers
aaron.ballman alexfh hokein Charusso
Diff Detail
Event Timeline
| clang-tools-extra/docs/ReleaseNotes.rst | ||
|---|---|---|
| 200 | Please use double back-ticks to highlight putenv. | |
| clang-tools-extra/clang-tidy/cert/PutenvWithAutoCheck.cpp | ||
|---|---|---|
| 29 | I think `alloca` allocates memory on stack, so thats why I didn't include it here. | |
| clang-tools-extra/clang-tidy/cert/PutenvWithAutoCheck.cpp | ||
|---|---|---|
| 27 | I don't know that this is sufficient for the check, and I sort of think this may need to be implemented by the static analyzer rather than clang-tidy. The initialization of the variable is going to be control flow sensitive. Consider something like: void foo(void) {
char *buffer = "huttah!";
if (rand() % 2 == 0) {
buffer = malloc(5);
strcpy(buffer, "woot");
}
putenv(buffer);
}
void bar(void) {
char *buffer = malloc(5);
strcpy(buffer, "woot");
if (rand() % 2 == 0) {
free(buffer);
buffer = "blah blah blah";
}
putenv(buffer);
} | |
| clang-tools-extra/docs/clang-tidy/checks/cert-pos34-c.rst | ||
| 4 | Underlining looks incorrect here. | |
| 6 | Finds calls to the `putenv` function which pass a pointer to an automatic variable as the argument. | |
| 23 | CERT Standard -> CERT C Coding Standard | |
| clang-tools-extra/clang-tidy/cert/PutenvWithAutoCheck.cpp | ||
|---|---|---|
| 27 | Yes, I see your point. I will try to rewrite it as SA checker. | |
Extra space.