Content-Length: 460391 | pFad | http://github.com/github/codeql/commit/0822ded899dcca156a4c422fd00e110e2dae9899

6C Merge pull request #19569 from MathiasVP/fix-return-value-surces-in-mad · github/codeql@0822ded · GitHub
Skip to content

Commit 0822ded

Browse files
authored
Merge pull request #19569 from MathiasVP/fix-return-value-surces-in-mad
Shared/C++: Handle non-standard return values in MaD flow sources/sinks
2 parents 1b2d23b + 92e0b64 commit 0822ded

File tree

3 files changed

+39
-11
lines changed

3 files changed

+39
-11
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ module Input implements InputSig<Location, DataFlowImplSpecific::CppDataFlow> {
2222

2323
ArgumentPosition callbackSelfParameterPosition() { result = TDirectPosition(-1) }
2424

25-
ReturnKind getStandardReturnValueKind() { result.(NormalReturnKind).getIndirectionIndex() = 0 }
25+
ReturnKind getStandardReturnValueKind() { result = getReturnValueKind("") }
26+
27+
ReturnKind getReturnValueKind(string arg) {
28+
arg = repeatStars(result.(NormalReturnKind).getIndirectionIndex())
29+
}
2630

2731
string encodeParameterPosition(ParameterPosition pos) { result = pos.toString() }
2832

cpp/ql/test/library-tests/dataflow/models-as-data/tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ void test_sources() {
5656
sink(v_direct); // $ ir
5757

5858
sink(remoteMadSourceIndirect());
59-
sink(*remoteMadSourceIndirect()); // $ MISSING: ir
59+
sink(*remoteMadSourceIndirect()); // $ ir
6060
sink(*remoteMadSourceDoubleIndirect());
61-
sink(**remoteMadSourceDoubleIndirect()); // $ MISSING: ir
61+
sink(**remoteMadSourceDoubleIndirect()); // $ ir
6262

6363
int a, b, c, d;
6464

@@ -124,7 +124,7 @@ void test_sinks() {
124124
// test sources + sinks together
125125

126126
madSinkArg0(localMadSource()); // $ ir
127-
madSinkIndirectArg0(remoteMadSourceIndirect()); // $ MISSING: ir
127+
madSinkIndirectArg0(remoteMadSourceIndirect()); // $ ir
128128
madSinkVar = remoteMadSourceVar; // $ ir
129129
*madSinkVarIndirect = remoteMadSourceVar; // $ MISSING: ir
130130
}

shared/dataflow/codeql/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@ signature module InputSig<LocationSig Location, DF::InputSig<Location> Lang> {
5454
/** Gets the return kind corresponding to specification `"ReturnValue"`. */
5555
Lang::ReturnKind getStandardReturnValueKind();
5656

57+
/**
58+
* Gets the return kind corresponding to specification `"ReturnValue"` when
59+
* supplied with the argument `arg`.
60+
*
61+
* Note that it is expected that the following equality holds:
62+
* ```
63+
* getReturnValueKind("") = getStandardReturnValueKind()
64+
* ```
65+
*/
66+
default Lang::ReturnKind getReturnValueKind(string arg) {
67+
arg = "" and
68+
result = getStandardReturnValueKind()
69+
}
70+
5771
/** Gets the textual representation of parameter position `pos` used in MaD. */
5872
string encodeParameterPosition(Lang::ParameterPosition pos);
5973

@@ -2164,9 +2178,15 @@ module Make<
21642178
)
21652179
)
21662180
or
2167-
c = "ReturnValue" and
2168-
node.asNode() =
2169-
getAnOutNodeExt(mid.asCall(), TValueReturn(getStandardReturnValueKind()))
2181+
c.getName() = "ReturnValue" and
2182+
exists(ReturnKind rk |
2183+
not exists(c.getAnArgument()) and
2184+
rk = getStandardReturnValueKind()
2185+
or
2186+
rk = getReturnValueKind(c.getAnArgument())
2187+
|
2188+
node.asNode() = getAnOutNodeExt(mid.asCall(), TValueReturn(rk))
2189+
)
21702190
or
21712191
SourceSinkInterpretationInput::interpretOutput(c, mid, node)
21722192
)
@@ -2198,12 +2218,16 @@ module Make<
21982218
)
21992219
)
22002220
or
2201-
exists(ReturnNode ret, ValueReturnKind kind |
2202-
c = "ReturnValue" and
2221+
exists(ReturnNode ret, ReturnKind kind |
2222+
c.getName() = "ReturnValue" and
22032223
ret = node.asNode() and
2204-
kind.getKind() = ret.getKind() and
2205-
kind.getKind() = getStandardReturnValueKind() and
2224+
kind = ret.getKind() and
22062225
mid.asCallable() = getNodeEnclosingCallable(ret)
2226+
|
2227+
not exists(c.getAnArgument()) and
2228+
kind = getStandardReturnValueKind()
2229+
or
2230+
kind = getReturnValueKind(c.getAnArgument())
22072231
)
22082232
or
22092233
SourceSinkInterpretationInput::interpretInput(c, mid, node)

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/github/codeql/commit/0822ded899dcca156a4c422fd00e110e2dae9899

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy