secure-software-engineering / phasar

A LLVM-based static analysis framework.
Other
930 stars 140 forks source link

Fix Configuration Undefined Behavior #505

Closed fabianbs96 closed 2 years ago

fabianbs96 commented 2 years ago

In the TestConfig PathToLLTestFiles, PathToTxtTestFiles and PathToJSONTestFiles are globals that depend on the global Configuration::PhasarDir. However, the initialization order of global variables is not defined, so at initialization-time of the three globals from the TestConfig, the PhasarDir might not have been initialized yet leading to undefined behavior. This might materialize in the unittests not finding the llvm test files.

The fix makes PhasarDir a static local inside Configuration::PhasarDirectory(). Here, it is guaranteed by the standard that the static local variable is initialized exactly once the first time the enclosing function is being called.