Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 448a901

Browse files
committed
C++: Compute the number of indirections from MaD using a new predicate.
1 parent 2159256 commit 448a901

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

cpp/ql/lib/semmle/code/cpp/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,3 +262,22 @@ module Private {
262262
}
263263

264264
module Public = Impl::Public;
265+
266+
/**
267+
* Gets the number of indirections that can be returned by the function
268+
* modelled using the given MaD row.
269+
*/
270+
int indirectionForModelledFunction(
271+
string namespace, string type, boolean subtypes, string name, string signature, string ext,
272+
string input, string output, string kind, string provenance
273+
) {
274+
summaryModel(namespace, type, subtypes, name, signature, ext, input, output, kind, provenance) and
275+
(
276+
// Return the number of stars in `ReturnValue[...]`
277+
result = output.regexpCapture("ReturnValue\\[(\\*+)\\]", 1).length()
278+
or
279+
// There are no brackets the result is 0
280+
output = "ReturnValue" and
281+
result = 0
282+
)
283+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,8 @@ private newtype TReturnKind =
459459
TNormalReturnKind(int indirectionIndex) {
460460
Ssa::hasIndirectOperand(any(ReturnValueInstruction ret).getReturnAddressOperand(),
461461
indirectionIndex + 1) // We subtract one because the return loads the value.
462+
or
463+
indirectionIndex = FlowSummaryImpl::indirectionForModelledFunction(_, _, _, _, _, _, _, _, _, _)
462464
} or
463465
TIndirectReturnKind(int argumentIndex, int indirectionIndex) {
464466
exists(Ssa::FinalParameterUse use |

0 commit comments

Comments
 (0)