Skip to content

Commit 68a661f

Browse files
committed
Write out whole function names
1 parent b79711b commit 68a661f

File tree

5 files changed

+25
-17
lines changed

5 files changed

+25
-17
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ module BeegoOrm {
1818
DbSink() {
1919
exists(Method m, string methodName, int argNum |
2020
m.hasQualifiedName(packagePath(), "DB", methodName) and
21-
methodName in [
22-
"Exec", "ExecContext", "Prepare", "PrepareContext", "Query", "QueryContext", "QueryRow",
23-
"QueryRowContext"
24-
] and
25-
if methodName.matches("%Context") then argNum = 1 else argNum = 0
21+
(
22+
methodName = ["Exec", "Prepare", "Query", "QueryRow"] and
23+
argNum = 0
24+
or
25+
methodName = ["ExecContext", "PrepareContext", "QueryContext", "QueryRowContext"] and
26+
argNum = 1
27+
)
2628
|
2729
this = m.getACall().getArgument(argNum)
2830
)

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ module Logrus {
1515
}
1616

1717
bindingset[result]
18-
private string getAnEntryUpdatingMethodName() { result.regexpMatch("With(Error|Fields?|Time)") }
18+
private string getAnEntryUpdatingMethodName() {
19+
result = ["WithError", "WithField", "WithFields", "WithTime"]
20+
}
1921

2022
private class LogFunction extends Function {
2123
LogFunction() {

go/ql/lib/semmle/go/frameworks/stdlib/Fmt.qll

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ module Fmt {
1313
* The `Sprint` or `Append` functions or one of their variants.
1414
*/
1515
deprecated class AppenderOrSprinter extends TaintTracking::FunctionModel {
16-
AppenderOrSprinter() { this.hasQualifiedName("fmt", ["Append", "Sprint"] + ["", "f", "ln"]) }
16+
AppenderOrSprinter() {
17+
this.hasQualifiedName("fmt",
18+
["Append", "Appendf", "Appendln", "Sprint", "Sprintf", "Sprintln"])
19+
}
1720

1821
override predicate hasTaintFlow(FunctionInput inp, FunctionOutput outp) {
1922
inp.isParameter(_) and outp.isResult()
@@ -23,13 +26,14 @@ module Fmt {
2326
/** The `Sprint` or `Append` functions or one of their variants. */
2427
class AppenderOrSprinterFunc extends Function {
2528
AppenderOrSprinterFunc() {
26-
this.hasQualifiedName("fmt", ["Append", "Sprint"] + ["", "f", "ln"])
29+
this.hasQualifiedName("fmt",
30+
["Append", "Appendf", "Appendln", "Sprint", "Sprintf", "Sprintln"])
2731
}
2832
}
2933

3034
/** The `Sprint` function or one of its variants. */
3135
class Sprinter extends AppenderOrSprinterFunc {
32-
Sprinter() { this.getName().matches("Sprint%") }
36+
Sprinter() { this.getName() = ["Sprint", "Sprintf", "Sprintln"] }
3337
}
3438

3539
/** The `Print` function or one of its variants. */

go/ql/lib/semmle/go/frameworks/stdlib/HtmlTemplate.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ module HtmlTemplate {
1111

1212
TemplateEscape() {
1313
exists(string fn |
14-
fn.matches("HTMLEscape%") and kind = "html"
14+
fn = ["HTMLEscape", "HTMLEscapeString", "HTMLEscaper"] and kind = "html"
1515
or
16-
fn.matches("JSEscape%") and kind = "js"
16+
fn = ["JSEscape", "JSEscapeString", "JSEscaper"] and kind = "js"
1717
or
18-
fn.matches("URLQueryEscape%") and kind = "url"
18+
fn = "URLQueryEscaper" and kind = "url"
1919
|
2020
this.hasQualifiedName("html/template", fn)
2121
)

go/ql/lib/semmle/go/frameworks/stdlib/Log.qll

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

1212
LogFunction() {
1313
exists(string fn |
14-
fn.matches(["Fatal%", "Panic%", "Print%"]) and firstPrintedArg = 0
14+
fn =
15+
["Fatal", "Fatalf", "Fatalln", "Panic", "Panicf", "Panicln", "Print", "Printf", "Println"] and
16+
firstPrintedArg = 0
1517
or
1618
fn = "Output" and firstPrintedArg = 1
1719
|
@@ -25,7 +27,7 @@ module Log {
2527
}
2628

2729
private class LogFormatter extends StringOps::Formatting::Range instanceof LogFunction {
28-
LogFormatter() { this.getName().matches("%f") }
30+
LogFormatter() { this.getName() = ["Fatalf", "Panicf", "Printf"] }
2931

3032
override int getFormatStringIndex() { result = 0 }
3133
}
@@ -42,9 +44,7 @@ module Log {
4244

4345
/** A fatal log function, which calls `os.Exit`. */
4446
private class FatalLogFunction extends Function {
45-
FatalLogFunction() {
46-
exists(string fn | fn.matches("Fatal%") | this.hasQualifiedName("log", fn))
47-
}
47+
FatalLogFunction() { this.hasQualifiedName("log", ["Fatal", "Fatalf", "Fatalln"]) }
4848

4949
override predicate mayReturnNormally() { none() }
5050
}

0 commit comments

Comments
 (0)