Files
codeql/cpp/ql/src/Critical/InitialisationNotRun.ql
Jonas Jensen 64a87a863c C++: Remove uses of getQualifiedName
This removes all uses of `Declaration.getQualifiedName` that I think can
be removed without changing any behaviour. The following uses in the
LGTM default suite remain:

* `cpp/ql/src/Security/CWE/CWE-121/UnterminatedVarargsCall.ql` (in `select`).
* `cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowDispatch.qll` (needs template args).
* `cpp/ql/src/semmle/code/cpp/security/FunctionWithWrappers.qll` (used for alert messages).
2019-05-03 10:37:48 +02:00

43 lines
1.0 KiB
Plaintext

/**
* @name Initialization code not run
* @description Not running initialization code may lead to unexpected behavior.
* @kind problem
* @id cpp/initialization-not-run
* @problem.severity warning
* @tags reliability
* security
* external/cwe/cwe-456
*/
import cpp
import semmle.code.cpp.pointsto.CallGraph
predicate global(GlobalVariable v) {
not exists(v.getInitializer()) and
not v.getType() instanceof ArrayType and
not v.getType() instanceof Class and
v.getAnAccess().isUsedAsLValue()
}
predicate mainCalled(Function f) {
f.hasGlobalName("main")
or
exists(Function caller | mainCalled(caller) and allCalls(caller, f))
}
predicate called(Function f) {
mainCalled(f)
or
exists(FunctionAccess fa | fa.getTarget() = f)
}
from GlobalVariable v
where
global(v) and
not exists(VariableAccess lval |
v.getAnAccess() = lval and
lval.isUsedAsLValue() and
called(lval.getEnclosingFunction())
)
select v, "Initialization code for '" + v.getName() + "' is never run."