-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathSpew.qll
More file actions
45 lines (36 loc) · 1.5 KB
/
Spew.qll
File metadata and controls
45 lines (36 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* Provides models of commonly used functions in the `github.com/davecgh/go-spew/spew` package.
*/
import go
/**
* Provides models of commonly used functions in the `github.com/davecgh/go-spew/spew` package.
*/
module Spew {
/** Gets the package path `github.com/davecgh/go-spew/spew`. */
private string packagePath() { result = package("github.com/davecgh/go-spew", "spew") }
private class SpewFunction extends Function {
int firstPrintedArg;
SpewFunction() {
exists(string fn |
fn in ["Dump", "Errorf", "Print", "Printf", "Println"] and firstPrintedArg = 0
or
fn in ["Fdump", "Fprint", "Fprintf", "Fprintln"] and firstPrintedArg = 1
|
this.hasQualifiedName(packagePath(), fn)
)
}
int getFirstPrintedArg() { result = firstPrintedArg }
}
private class StringFormatter extends StringOps::Formatting::Range instanceof SpewFunction {
StringFormatter() { this.getName().matches("%f") }
override int getFormatStringIndex() { result = super.getFirstPrintedArg() }
}
// These are expressed using TaintTracking::FunctionModel because varargs functions don't work with Models-as-Data sumamries yet.
/** The `Sprint` function or one of its variants. */
class Sprinter extends TaintTracking::FunctionModel {
Sprinter() { this.hasQualifiedName(packagePath(), ["Sdump", "Sprint", "Sprintln", "Sprintf"]) }
override predicate hasTaintFlow(FunctionInput inp, FunctionOutput outp) {
inp.isParameter(_) and outp.isResult()
}
}
}