Skip to content

Commit ff9a4d0

Browse files
authored
Merge pull request #18592 from MathiasVP/fix-enclosing-callable-cpp
C++: Don't generate dataflow nodes for functions with summaries
2 parents f0755bf + 38b66e5 commit ff9a4d0

File tree

10 files changed

+181
-66
lines changed

10 files changed

+181
-66
lines changed

cpp/ql/lib/experimental/cryptography/modules/OpenSSL.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ module LiteralAlgorithmTracerConfig implements DataFlow::ConfigSig {
8787
// False positives in OpenSSL also observed for CRYPTO_strndup (filtering any CRYPTO_* function)
8888
// due to setting a null byte in the string
8989
(
90-
isPossibleOpenSSLFunction(source.getEnclosingCallable())
90+
isPossibleOpenSSLFunction(source.getFunction())
9191
implies
9292
(
93-
not source.getEnclosingCallable().getName().matches("OBJ_%") and
94-
not source.getEnclosingCallable().getName().matches("CRYPTO_%")
93+
not source.getFunction().getName().matches("OBJ_%") and
94+
not source.getFunction().getName().matches("CRYPTO_%")
9595
)
9696
)
9797
}

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowDispatch.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ private module VirtualDispatch {
152152
ReturnNode node, ReturnKind kind, DataFlowCallable callable
153153
) {
154154
node.getKind() = kind and
155-
node.getEnclosingCallable() = callable.getUnderlyingCallable()
155+
node.getFunction() = callable.getUnderlyingCallable()
156156
}
157157

158158
/** Call through a function pointer. */

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowPrivate.qll

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,7 @@ private module IndirectInstructions {
333333
import IndirectInstructions
334334

335335
/** Gets the callable in which this node occurs. */
336-
DataFlowCallable nodeGetEnclosingCallable(Node n) {
337-
result.getUnderlyingCallable() = n.getEnclosingCallable()
338-
}
336+
DataFlowCallable nodeGetEnclosingCallable(Node n) { result = n.getEnclosingCallable() }
339337

340338
/** Holds if `p` is a `ParameterNode` of `c` with position `pos`. */
341339
predicate isParameterNode(ParameterNode p, DataFlowCallable c, ParameterPosition pos) {
@@ -1011,10 +1009,8 @@ class CastNode extends Node {
10111009
}
10121010

10131011
cached
1014-
private newtype TDataFlowCallable =
1015-
TSourceCallable(Cpp::Declaration decl) {
1016-
not decl instanceof FlowSummaryImpl::Public::SummarizedCallable
1017-
} or
1012+
newtype TDataFlowCallable =
1013+
TSourceCallable(Cpp::Declaration decl) or
10181014
TSummarizedCallable(FlowSummaryImpl::Public::SummarizedCallable c)
10191015

10201016
/**
@@ -1127,7 +1123,21 @@ class DataFlowCall extends TDataFlowCall {
11271123
/**
11281124
* Gets the `Function` that the call targets, if this is statically known.
11291125
*/
1130-
DataFlowCallable getStaticCallTarget() { none() }
1126+
Function getStaticCallSourceTarget() { none() }
1127+
1128+
/**
1129+
* Gets the target of this call. If a summarized callable exists for the
1130+
* target this is chosen, and otherwise the callable is the implementation
1131+
* from the source code.
1132+
*/
1133+
DataFlowCallable getStaticCallTarget() {
1134+
exists(Function target | target = this.getStaticCallSourceTarget() |
1135+
not exists(TSummarizedCallable(target)) and
1136+
result.asSourceCallable() = target
1137+
or
1138+
result.asSummarizedCallable() = target
1139+
)
1140+
}
11311141

11321142
/**
11331143
* Gets the `index`'th argument operand. The qualifier is considered to have index `-1`.
@@ -1173,14 +1183,12 @@ private class NormalCall extends DataFlowCall, TNormalCall {
11731183

11741184
override CallTargetOperand getCallTargetOperand() { result = call.getCallTargetOperand() }
11751185

1176-
override DataFlowCallable getStaticCallTarget() {
1177-
result.getUnderlyingCallable() = call.getStaticCallTarget()
1178-
}
1186+
override Function getStaticCallSourceTarget() { result = call.getStaticCallTarget() }
11791187

11801188
override ArgumentOperand getArgumentOperand(int index) { result = call.getArgumentOperand(index) }
11811189

11821190
override DataFlowCallable getEnclosingCallable() {
1183-
result.getUnderlyingCallable() = call.getEnclosingFunction()
1191+
result.asSourceCallable() = call.getEnclosingFunction()
11841192
}
11851193

11861194
override string toString() { result = call.toString() }

0 commit comments

Comments
 (0)