Skip to content

Commit 8763d18

Browse files
committed
C#: Correct printing of out and ref notes in the model generator.
1 parent bcefdc8 commit 8763d18

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

csharp/ql/src/utils/modelgenerator/internal/CaptureModels.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@ module ModelGeneratorInput implements ModelGeneratorInputSig<Location, CsharpDat
233233
result = ParamReturnNodeAsOutput<parameterContentAccess/1>::paramReturnNodeAsOutput(c, pos)
234234
}
235235

236+
ParameterPosition getReturnKindParamPosition(ReturnKind kind) {
237+
kind.(OutRefReturnKind).getPosition() = result.getPosition()
238+
}
239+
236240
Callable returnNodeEnclosingCallable(DataFlow::Node ret) {
237241
result = DataFlowImplCommon::getNodeEnclosingCallable(ret).asCallable(_)
238242
}

shared/mad/codeql/mad/modelgenerator/internal/ModelGeneratorImpl.qll

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@ signature module ModelGeneratorInputSig<LocationSig Location, InputSig<Location>
221221
*/
222222
string printContent(Lang::ContentSet c);
223223

224+
/**
225+
* Gets the parameter position of the return kind, if any.
226+
*/
227+
default Lang::ParameterPosition getReturnKindParamPosition(Lang::ReturnKind node) { none() }
228+
224229
/**
225230
* Holds if it is irrelevant to generate models for `api` based on data flow analysis.
226231
*
@@ -301,6 +306,14 @@ module MakeModelGenerator<
301306
* Gets the kind of the return node.
302307
*/
303308
DataFlow::ReturnKindExt getKind() { result = kind }
309+
310+
/**
311+
* Gets the parameter position of the return node, if any.
312+
*/
313+
DataFlow::ParameterPosition getPosition() {
314+
result = this.getKind().(DataFlow::ParamUpdateReturnKind).getPosition() or
315+
result = getReturnKindParamPosition(this.getKind().(DataFlow::ValueReturnKind).getKind())
316+
}
304317
}
305318

306319
bindingset[c]
@@ -309,10 +322,11 @@ module MakeModelGenerator<
309322
private module PrintReturnNodeExt<printCallableParamSig/2 printCallableParam> {
310323
string getOutput(ReturnNodeExt node) {
311324
node.getKind() instanceof DataFlow::ValueReturnKind and
325+
not exists(node.getPosition()) and
312326
result = "ReturnValue"
313327
or
314328
exists(DataFlow::ParameterPosition pos |
315-
pos = node.getKind().(DataFlow::ParamUpdateReturnKind).getPosition() and
329+
pos = node.getPosition() and
316330
result = printCallableParam(returnNodeEnclosingCallable(node), pos)
317331
)
318332
}

0 commit comments

Comments
 (0)