Skip to content

Commit fe1a473

Browse files
authored
Merge pull request github#138 from github/erik-krogh/bump-this
bump the severity of `ql/implicit-this`
2 parents e25f03f + 3ebf1e3 commit fe1a473

File tree

377 files changed

+11868
-7654
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

377 files changed

+11868
-7654
lines changed

ql/src/queries/style/ImplicitThis.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* @name Using implicit `this`
33
* @description Writing member predicate calls with an implicit `this` can be confusing
44
* @kind problem
5-
* @problem.severity recommendation
6-
* @precision very-high
5+
* @problem.severity warning
6+
* @precision high
77
* @id ql/implicit-this
88
* @tags maintainability
99
*/

repo-tests/codeql-go.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4cae4b23fc1b2b1760e259b660996e9bb5573279
1+
894102defd0777931a0e261ad66e631e63ec0ad8

repo-tests/codeql-go/ql/lib/semmle/go/Decls.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ class FuncDef extends @funcdef, StmtParent, ExprParent {
137137
*/
138138
DataFlow::CallNode getACall() { result.getACallee() = this }
139139

140-
predicate isVariadic() { getType().isVariadic() }
140+
/** Holds if this function is variadic. */
141+
predicate isVariadic() { this.getType().isVariadic() }
141142

142143
override string getAPrimaryQlClass() { result = "FuncDef" }
143144
}

repo-tests/codeql-go/ql/lib/semmle/go/Scopes.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,10 +377,11 @@ class Function extends ValueEntity, @functionobject {
377377
/** Gets the declaration of this function, if any. */
378378
FuncDecl getFuncDecl() { none() }
379379

380+
/** Holds if this function is variadic. */
380381
predicate isVariadic() {
381382
this.(BuiltinFunction).getName() = ["append", "make", "print", "println"]
382383
or
383-
this.(DeclaredFunction).getFuncDecl().isVariadic()
384+
this.(DeclaredFunction).getType().(SignatureType).isVariadic()
384385
}
385386

386387
/** Holds if this function has no observable side effects. */

repo-tests/codeql-go/ql/lib/semmle/go/dataflow/barrierguardutil/RegexpCheck.qll

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,26 @@ import go
88
* A call to a regexp match function, considered as a barrier guard for sanitizing untrusted URLs.
99
*
1010
* This is overapproximate: we do not attempt to reason about the correctness of the regexp.
11+
*
12+
* Use this if you want to define a derived `DataFlow::BarrierGuard` without
13+
* make the type recursive. Otherwise use `RegexpCheck`.
1114
*/
12-
class RegexpCheck extends DataFlow::BarrierGuard {
13-
RegexpMatchFunction matchfn;
14-
DataFlow::CallNode call;
15-
16-
RegexpCheck() {
15+
predicate regexpFunctionChecksExpr(DataFlow::Node resultNode, Expr checked, boolean branch) {
16+
exists(RegexpMatchFunction matchfn, DataFlow::CallNode call |
1717
matchfn.getACall() = call and
18-
this = matchfn.getResult().getNode(call).getASuccessor*()
19-
}
20-
21-
override predicate checks(Expr e, boolean branch) {
22-
e = matchfn.getValue().getNode(call).asExpr() and
18+
resultNode = matchfn.getResult().getNode(call).getASuccessor*() and
19+
checked = matchfn.getValue().getNode(call).asExpr() and
2320
(branch = false or branch = true)
24-
}
21+
)
22+
}
23+
24+
/**
25+
* A call to a regexp match function, considered as a barrier guard for sanitizing untrusted URLs.
26+
*
27+
* This is overapproximate: we do not attempt to reason about the correctness of the regexp.
28+
*/
29+
class RegexpCheck extends DataFlow::BarrierGuard {
30+
RegexpCheck() { regexpFunctionChecksExpr(this, _, _) }
31+
32+
override predicate checks(Expr e, boolean branch) { regexpFunctionChecksExpr(this, e, branch) }
2533
}

repo-tests/codeql-go/ql/lib/semmle/go/frameworks/Glog.qll

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,17 @@ import go
1111
*/
1212
module Glog {
1313
private class GlogCall extends LoggerCall::Range, DataFlow::CallNode {
14+
int firstPrintedArg;
15+
1416
GlogCall() {
15-
exists(string pkg, Function f, string fn |
17+
exists(string pkg, Function f, string fn, string level |
1618
pkg = package(["github.com/golang/glog", "gopkg.in/glog", "k8s.io/klog"], "") and
17-
fn.regexpMatch("(Error|Exit|Fatal|Info|Warning)(|f|ln)") and
19+
level = ["Error", "Exit", "Fatal", "Info", "Warning"] and
20+
(
21+
fn = level + ["", "f", "ln"] and firstPrintedArg = 0
22+
or
23+
fn = level + "Depth" and firstPrintedArg = 1
24+
) and
1825
this = f.getACall()
1926
|
2027
f.hasQualifiedName(pkg, fn)
@@ -23,6 +30,8 @@ module Glog {
2330
)
2431
}
2532

26-
override DataFlow::Node getAMessageComponent() { result = this.getAnArgument() }
33+
override DataFlow::Node getAMessageComponent() {
34+
result = this.getArgument(any(int i | i >= firstPrintedArg))
35+
}
2736
}
2837
}

repo-tests/codeql-go/ql/lib/semmle/go/frameworks/Logrus.qll

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ module Logrus {
1111

1212
bindingset[result]
1313
private string getALogResultName() {
14-
result.matches(["Debug%", "Error%", "Fatal%", "Info%", "Panic%", "Print%", "Trace%", "Warn%"])
14+
result
15+
.matches([
16+
"Debug%", "Error%", "Fatal%", "Info%", "Log%", "Panic%", "Print%", "Trace%", "Warn%"
17+
])
1518
}
1619

1720
bindingset[result]
@@ -23,7 +26,7 @@ module Logrus {
2326
LogCall() {
2427
exists(string name | name = getALogResultName() or name = getAnEntryUpdatingMethodName() |
2528
this.getTarget().hasQualifiedName(packagePath(), name) or
26-
this.getTarget().(Method).hasQualifiedName(packagePath(), "Entry", name)
29+
this.getTarget().(Method).hasQualifiedName(packagePath(), ["Entry", "Logger"], name)
2730
)
2831
}
2932

repo-tests/codeql-go/ql/lib/semmle/go/frameworks/SQL.qll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,11 @@ module SQL {
8888
// first argument to `squirrel.Expr`
8989
fn.hasQualifiedName(sq, "Expr")
9090
or
91-
// first argument to the `Prefix` or `Suffix` method of one of the `*Builder` classes
91+
// first argument to the `Prefix`, `Suffix` or `Where` method of one of the `*Builder` classes
9292
exists(string builder | builder.matches("%Builder") |
9393
fn.(Method).hasQualifiedName(sq, builder, "Prefix") or
94-
fn.(Method).hasQualifiedName(sq, builder, "Suffix")
94+
fn.(Method).hasQualifiedName(sq, builder, "Suffix") or
95+
fn.(Method).hasQualifiedName(sq, builder, "Where")
9596
)
9697
) and
9798
this = fn.getACall().getArgument(0) and

repo-tests/codeql-go/ql/lib/semmle/go/frameworks/stdlib/Log.qll

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,7 @@ import go
88
module Log {
99
private class LogCall extends LoggerCall::Range, DataFlow::CallNode {
1010
LogCall() {
11-
exists(string fn |
12-
fn.matches("Fatal%")
13-
or
14-
fn.matches("Panic%")
15-
or
16-
fn.matches("Print%")
17-
|
11+
exists(string fn | fn.matches(["Fatal%", "Panic%", "Print%"]) |
1812
this.getTarget().hasQualifiedName("log", fn)
1913
or
2014
this.getTarget().(Method).hasQualifiedName("log", "Logger", fn)

repo-tests/codeql-go/ql/lib/semmle/go/security/IncorrectIntegerConversionLib.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class ConversionWithoutBoundsCheckConfig extends TaintTracking::Configuration {
124124
)
125125
}
126126

127-
override predicate isSink(DataFlow::Node sink) { isSink(sink, sinkBitSize) }
127+
override predicate isSink(DataFlow::Node sink) { this.isSink(sink, sinkBitSize) }
128128

129129
override predicate isSanitizerGuard(DataFlow::BarrierGuard guard) {
130130
// To catch flows that only happen on 32-bit architectures we
@@ -136,7 +136,7 @@ class ConversionWithoutBoundsCheckConfig extends TaintTracking::Configuration {
136136

137137
override predicate isSanitizerOut(DataFlow::Node node) {
138138
exists(int bitSize | isIncorrectIntegerConversion(sourceBitSize, bitSize) |
139-
isSink(node, bitSize)
139+
this.isSink(node, bitSize)
140140
)
141141
}
142142
}

0 commit comments

Comments
 (0)