Skip to content

Commit 4f93f2b

Browse files
authored
Merge pull request #10076 from erik-krogh/ql-for-ql-fixes
various QL-for-QL fixes
2 parents 61a2c0d + 9e7c0c6 commit 4f93f2b

File tree

30 files changed

+51
-65
lines changed

30 files changed

+51
-65
lines changed

cpp/ql/lib/experimental/semmle/code/cpp/semantic/SemanticExprSpecific.qll

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,22 +292,20 @@ module SemanticExprConfig {
292292

293293
class Guard = IRGuards::IRGuardCondition;
294294

295-
predicate guard(Guard guard, BasicBlock block) {
296-
block = guard.(IRGuards::IRGuardCondition).getBlock()
297-
}
295+
predicate guard(Guard guard, BasicBlock block) { block = guard.getBlock() }
298296

299297
Expr getGuardAsExpr(Guard guard) { result = guard }
300298

301299
predicate equalityGuard(Guard guard, Expr e1, Expr e2, boolean polarity) {
302-
guard.(IRGuards::IRGuardCondition).comparesEq(e1.getAUse(), e2.getAUse(), 0, true, polarity)
300+
guard.comparesEq(e1.getAUse(), e2.getAUse(), 0, true, polarity)
303301
}
304302

305303
predicate guardDirectlyControlsBlock(Guard guard, BasicBlock controlled, boolean branch) {
306-
guard.(IRGuards::IRGuardCondition).controls(controlled, branch)
304+
guard.controls(controlled, branch)
307305
}
308306

309307
predicate guardHasBranchEdge(Guard guard, BasicBlock bb1, BasicBlock bb2, boolean branch) {
310-
guard.(IRGuards::IRGuardCondition).controlsEdge(bb1, bb2, branch)
308+
guard.controlsEdge(bb1, bb2, branch)
311309
}
312310

313311
Guard comparisonGuard(Expr e) { result = e }

cpp/ql/src/Likely Bugs/Memory Management/UsingExpiredStackAddress.ql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,11 @@ class PathElement extends TPathElement {
268268
predicate isSink(IRBlock block) { exists(this.asSink(block)) }
269269

270270
string toString() {
271-
result = [asStore().toString(), asCall(_).toString(), asMid().toString(), asSink(_).toString()]
271+
result =
272+
[
273+
this.asStore().toString(), this.asCall(_).toString(), this.asMid().toString(),
274+
this.asSink(_).toString()
275+
]
272276
}
273277

274278
predicate hasLocationInfo(

cpp/ql/src/experimental/Security/CWE/CWE-125/DangerousWorksWithMultibyteOrWideCharacters.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ predicate findUseCharacterConversion(Expr exp, string msg) {
6767
exists(FunctionCall fc |
6868
fc = exp and
6969
(
70-
exists(Loop lptmp | lptmp = fc.getEnclosingStmt().getParentStmt*()) and
70+
fc.getEnclosingStmt().getParentStmt*() instanceof Loop and
7171
fc.getTarget().hasName(["mbtowc", "mbrtowc", "_mbtowc_l"]) and
7272
not fc.getArgument(0).isConstant() and
7373
not fc.getArgument(1).isConstant() and

cpp/ql/src/experimental/Security/CWE/CWE-190/DangerousUseOfTransformationAfterOperation.ql

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,8 @@ predicate conversionDoneLate(MulExpr mexp) {
4444
mexp.getEnclosingElement().(ComparisonOperation).hasOperands(mexp, e0) and
4545
e0.getType().getSize() = mexp.getConversion().getConversion().getType().getSize()
4646
or
47-
e0.(FunctionCall)
48-
.getTarget()
49-
.getParameter(argumentPosition(e0.(FunctionCall), mexp, _))
50-
.getType()
51-
.getSize() = mexp.getConversion().getConversion().getType().getSize()
47+
e0.(FunctionCall).getTarget().getParameter(argumentPosition(e0, mexp, _)).getType().getSize() =
48+
mexp.getConversion().getConversion().getType().getSize()
5249
)
5350
)
5451
}
@@ -75,7 +72,7 @@ predicate signSmallerWithEqualSizes(MulExpr mexp) {
7572
ae.getRValue().getUnderlyingType().(IntegralType).isUnsigned() and
7673
ae.getLValue().getUnderlyingType().(IntegralType).isSigned() and
7774
(
78-
not exists(DivExpr de | mexp.getParent*() = de)
75+
not mexp.getParent*() instanceof DivExpr
7976
or
8077
exists(DivExpr de, Expr ec |
8178
e2.isConstant() and

go/ql/lib/semmle/go/AST.qll

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ class AstNode extends @node, Locatable {
2828
/**
2929
* Gets a child node of this node.
3030
*/
31-
AstNode getAChild() { result = getChild(_) }
31+
AstNode getAChild() { result = this.getChild(_) }
3232

3333
/**
3434
* Gets the number of child nodes of this node.
3535
*/
36-
int getNumChild() { result = count(getAChild()) }
36+
int getNumChild() { result = count(this.getAChild()) }
3737

3838
/**
3939
* Gets a child with the given index and of the given kind, if one exists.
@@ -63,7 +63,7 @@ class AstNode extends @node, Locatable {
6363
AstNode getUniquelyNumberedChild(int index) {
6464
result =
6565
rank[index + 1](AstNode child, string kind, int i |
66-
child = getChildOfKind(kind, i)
66+
child = this.getChildOfKind(kind, i)
6767
|
6868
child order by kind, i
6969
)
@@ -74,17 +74,17 @@ class AstNode extends @node, Locatable {
7474

7575
/** Gets the parent node of this AST node, but without crossing function boundaries. */
7676
private AstNode parentInSameFunction() {
77-
result = getParent() and
77+
result = this.getParent() and
7878
not this instanceof FuncDef
7979
}
8080

8181
/** Gets the innermost function definition to which this AST node belongs, if any. */
82-
FuncDef getEnclosingFunction() { result = getParent().parentInSameFunction*() }
82+
FuncDef getEnclosingFunction() { result = this.getParent().parentInSameFunction*() }
8383

8484
/**
8585
* Gets a comma-separated list of the names of the primary CodeQL classes to which this element belongs.
8686
*/
87-
final string getPrimaryQlClasses() { result = concat(getAPrimaryQlClass(), ",") }
87+
final string getPrimaryQlClasses() { result = concat(this.getAPrimaryQlClass(), ",") }
8888

8989
/**
9090
* Gets the name of a primary CodeQL class to which this node belongs.
@@ -116,12 +116,12 @@ class ExprParent extends @exprparent, AstNode {
116116
/**
117117
* Gets an expression that is a child node of this node in the AST.
118118
*/
119-
Expr getAChildExpr() { result = getChildExpr(_) }
119+
Expr getAChildExpr() { result = this.getChildExpr(_) }
120120

121121
/**
122122
* Gets the number of child expressions of this node.
123123
*/
124-
int getNumChildExpr() { result = count(getAChildExpr()) }
124+
int getNumChildExpr() { result = count(this.getAChildExpr()) }
125125
}
126126

127127
/**
@@ -139,12 +139,12 @@ class GoModExprParent extends @modexprparent, AstNode {
139139
/**
140140
* Gets an expression that is a child node of this node in the AST.
141141
*/
142-
GoModExpr getAChildGoModExpr() { result = getChildGoModExpr(_) }
142+
GoModExpr getAChildGoModExpr() { result = this.getChildGoModExpr(_) }
143143

144144
/**
145145
* Gets the number of child expressions of this node.
146146
*/
147-
int getNumChildGoModExpr() { result = count(getAChildGoModExpr()) }
147+
int getNumChildGoModExpr() { result = count(this.getAChildGoModExpr()) }
148148
}
149149

150150
/**
@@ -162,12 +162,12 @@ class StmtParent extends @stmtparent, AstNode {
162162
/**
163163
* Gets a statement that is a child node of this node in the AST.
164164
*/
165-
Stmt getAChildStmt() { result = getChildStmt(_) }
165+
Stmt getAChildStmt() { result = this.getChildStmt(_) }
166166

167167
/**
168168
* Gets the number of child statements of this node.
169169
*/
170-
int getNumChildStmt() { result = count(getAChildStmt()) }
170+
int getNumChildStmt() { result = count(this.getAChildStmt()) }
171171
}
172172

173173
/**
@@ -185,12 +185,12 @@ class DeclParent extends @declparent, AstNode {
185185
/**
186186
* Gets a child declaration of this node in the AST.
187187
*/
188-
Decl getADecl() { result = getDecl(_) }
188+
Decl getADecl() { result = this.getDecl(_) }
189189

190190
/**
191191
* Gets the number of child declarations of this node.
192192
*/
193-
int getNumDecl() { result = count(getADecl()) }
193+
int getNumDecl() { result = count(this.getADecl()) }
194194
}
195195

196196
/**
@@ -208,12 +208,12 @@ class FieldParent extends @fieldparent, AstNode {
208208
/**
209209
* Gets a child field of this node in the AST.
210210
*/
211-
FieldBase getAField() { result = getField(_) }
211+
FieldBase getAField() { result = this.getField(_) }
212212

213213
/**
214214
* Gets the number of child fields of this node.
215215
*/
216-
int getNumFields() { result = count(getAField()) }
216+
int getNumFields() { result = count(this.getAField()) }
217217
}
218218

219219
/**

go/ql/lib/semmle/go/Types.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ class InterfaceType extends @interfacetype, CompositeType {
787787
* Note that the indexes are not contiguous.
788788
*/
789789
TypeSetLiteralType getDirectlyEmbeddedTypeSetLiteral(int index) {
790-
hasDirectlyEmbeddedType(index, result)
790+
this.hasDirectlyEmbeddedType(index, result)
791791
}
792792

793793
/**
@@ -798,7 +798,7 @@ class InterfaceType extends @interfacetype, CompositeType {
798798
TypeSetLiteralType getAnEmbeddedTypeSetLiteral() {
799799
result = this.getDirectlyEmbeddedTypeSetLiteral(_) or
800800
result =
801-
getADirectlyEmbeddedInterface()
801+
this.getADirectlyEmbeddedInterface()
802802
.getUnderlyingType()
803803
.(InterfaceType)
804804
.getAnEmbeddedTypeSetLiteral()

go/ql/lib/semmle/go/frameworks/ElazarlGoproxy.qll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
*/
44

55
import go
6-
private import semmle.go.StringOps
76

87
/**
98
* Provides classes for working with concepts relating to the [github.com/elazarl/goproxy](https://pkg.go.dev/github.com/elazarl/goproxy) package.

go/ql/lib/semmle/go/frameworks/Glog.qll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55

66
import go
7-
private import semmle.go.StringOps
87

98
/**
109
* Provides models of commonly used functions in the `github.com/golang/glog` packages and its

go/ql/lib/semmle/go/frameworks/Logrus.qll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/** Provides models of commonly used functions in the `github.com/sirupsen/logrus` package. */
22

33
import go
4-
private import semmle.go.StringOps
54

65
/** Provides models of commonly used functions in the `github.com/sirupsen/logrus` package. */
76
module Logrus {

go/ql/lib/semmle/go/frameworks/Spew.qll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
*/
44

55
import go
6-
private import semmle.go.StringOps
76

87
/**
98
* Provides models of commonly used functions in the `github.com/davecgh/go-spew/spew` package.

0 commit comments

Comments
 (0)