This is an archive of the discontinued LLVM Phabricator instance.

[analyzer] Bifurcate on getenv() calls
ClosedPublic

Authored by steakhal on Oct 6 2021, 10:19 AM.

Details

Summary

The getenv() function might return NULL just like any other function.
However, in case of getenv() a state-split seems justified since the
programmer should expect the failure of this function.

secure_getenv(const char *name) behaves the same way but is not handled right now.
Note that std::getenv() is also not handled.

Diff Detail

Event Timeline

steakhal created this revision.Oct 6 2021, 10:19 AM
steakhal requested review of this revision.Oct 6 2021, 10:19 AM
steakhal added inline comments.
clang/test/Analysis/std-c-library-functions.c
260

typo

NoQ added a comment.Oct 6 2021, 11:12 PM

a state-split seems justified since the programmer should expect the failure of this function

The programmer can often make an argument that his program is always run "in a controlled environment". It could be a system daemon that's only invoked by the system in a specific manner or it could be a custom server that's run only on one server machine fully controlled by the developer. So most of the time, yeah, it's probably a useful behavior, but sometimes people may want to disable it. Maybe we should make a single global setting, say, -analyzer-config assume-controlled-environment=... or something like that, that'd make the static analyzer produce less such bifurcations.

a state-split seems justified since the programmer should expect the failure of this function

The programmer can often make an argument that his program is always run "in a controlled environment". It could be a system daemon that's only invoked by the system in a specific manner or it could be a custom server that's run only on one server machine fully controlled by the developer. So most of the time, yeah, it's probably a useful behavior, but sometimes people may want to disable it. Maybe we should make a single global setting, say, -analyzer-config assume-controlled-environment=... or something like that, that'd make the static analyzer produce less such bifurcations.

Hmm, that seems reasonable. Check the child revision: D111296.

martong accepted this revision.Oct 12 2021, 8:23 AM

LGTM!

This revision is now accepted and ready to land.Oct 12 2021, 8:23 AM
This revision was landed with ongoing or failed builds.Oct 13 2021, 1:51 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptOct 13 2021, 1:51 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript