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

Skip to content

Commit 11ab7e2

Browse files
tausbnStephan Brandauer
authored andcommitted
Java: Share argument indexing logic
Adds a utility predicate for turning integer indices into the desired string representation.
1 parent 04b8bf3 commit 11ab7e2

3 files changed

Lines changed: 18 additions & 7 deletions

File tree

java/ql/src/Telemetry/AutomodelApplicationModeCharacteristics.qll

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,12 @@ module ApplicationCandidatesImpl implements SharedCharacteristics::CandidateSig
7777
(
7878
exists(Call c, int argIdx |
7979
e.asExpr() = c.getArgument(argIdx) and
80-
input = "Argument[" + argIdx + "]"
80+
input = AutomodelSharedUtil::getArgumentForIndex(argIdx)
8181
)
8282
or
83-
exists(Call c | e.asExpr() = c.getQualifier() and input = "Argument[this]")
83+
exists(Call c |
84+
e.asExpr() = c.getQualifier() and input = AutomodelSharedUtil::getArgumentForIndex(-1)
85+
)
8486
)
8587
}
8688

@@ -148,10 +150,11 @@ class ApplicationModeMetadataExtractor extends string {
148150
exists(Call call, Callable callable, int argIdx |
149151
call.getCallee() = callable and
150152
(
151-
e.asExpr() = call.getArgument(argIdx) and input = "Argument[" + argIdx + "]"
153+
e.asExpr() = call.getArgument(argIdx)
152154
or
153-
e.asExpr() = call.getQualifier() and argIdx = -1 and input = "Argument[this]"
155+
e.asExpr() = call.getQualifier() and argIdx = -1
154156
) and
157+
input = AutomodelSharedUtil::getArgumentForIndex(argIdx) and
155158
package = callable.getDeclaringType().getPackage().getName() and
156159
type = callable.getDeclaringType().getErasure().(RefType).nestedName() and
157160
subtypes = this.considerSubtypes(callable) and
@@ -231,7 +234,7 @@ private class NotAModelApiParameter extends CharacteristicsImpl::UninterestingTo
231234
exists(int argIdx | exists(api.getParameter(argIdx)) |
232235
argIdx = -1 and e.asExpr() = c.getQualifier()
233236
or
234-
argIdx >= 0 and e.asExpr() = c.getArgument(argIdx)
237+
e.asExpr() = c.getArgument(argIdx)
235238
)
236239
)
237240
)

java/ql/src/Telemetry/AutomodelFrameworkModeCharacteristics.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ module FrameworkCandidatesImpl implements SharedCharacteristics::CandidateSig {
7070
signature = ExternalFlow::paramsString(getCallable(e)) and
7171
ext = "" and
7272
exists(int paramIdx | e.isParameterOf(_, paramIdx) |
73-
if paramIdx = -1 then input = "Argument[this]" else input = "Argument[" + paramIdx + "]"
73+
input = AutomodelSharedUtil::getArgumentForIndex(paramIdx)
7474
)
7575
}
7676

@@ -134,7 +134,7 @@ class FrameworkModeMetadataExtractor extends string {
134134
) {
135135
exists(Callable callable, int paramIdx |
136136
e.asParameter() = callable.getParameter(paramIdx) and
137-
(if paramIdx = -1 then input = "Argument[this]" else input = "Argument[" + paramIdx + "]") and
137+
input = AutomodelSharedUtil::getArgumentForIndex(paramIdx) and
138138
package = callable.getDeclaringType().getPackage().getName() and
139139
type = callable.getDeclaringType().getErasure().(RefType).nestedName() and
140140
subtypes = this.considerSubtypes(callable) and

java/ql/src/Telemetry/AutomodelSharedUtil.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,11 @@ predicate isKnownKind(
4949
humanReadableKind = "command injection" and
5050
type instanceof AutomodelEndpointTypes::CommandInjectionSinkType
5151
}
52+
53+
/** Gets the argument name for the argument with the index `index`. */
54+
bindingset[index]
55+
string getArgumentForIndex(int index) {
56+
index = -1 and result = "Argument[this]"
57+
or
58+
index >= 0 and result = "Argument[" + index + "]"
59+
}

0 commit comments

Comments
 (0)