|
| 1 | +package main |
| 2 | + |
| 3 | +//go:generate depstubber -vendor github.com/davecgh/go-spew/spew "" Dump,Print,Println,Fdump,Fprint,Fprintln,Errorf,Fprintf,Printf,Sdump,Sprint,Sprintf,Sprintln |
| 4 | + |
| 5 | +import ( |
| 6 | + "io" |
| 7 | + |
| 8 | + "github.com/davecgh/go-spew/spew" |
| 9 | +) |
| 10 | + |
| 11 | +func main() {} |
| 12 | + |
| 13 | +type Person struct { |
| 14 | + Name string |
| 15 | + Address string |
| 16 | +} |
| 17 | + |
| 18 | +func getUntrustedString() string { return "%v" } |
| 19 | + |
| 20 | +func getUntrustedStruct() Person { return Person{} } |
| 21 | + |
| 22 | +func sinkString(s string) {} |
| 23 | + |
| 24 | +func testSpew(w io.Writer) { |
| 25 | + s := "%v" |
| 26 | + sUntrusted := getUntrustedString() |
| 27 | + p := Person{} |
| 28 | + pUntrusted := getUntrustedStruct() |
| 29 | + |
| 30 | + spew.Dump(pUntrusted) // NOT OK |
| 31 | + spew.Print(pUntrusted) // NOT OK |
| 32 | + spew.Println(pUntrusted) // NOT OK |
| 33 | + spew.Errorf(sUntrusted, p) // NOT OK |
| 34 | + spew.Errorf(s, pUntrusted) // NOT OK |
| 35 | + spew.Printf(sUntrusted, p) // NOT OK |
| 36 | + spew.Printf(s, pUntrusted) // NOT OK |
| 37 | + |
| 38 | + spew.Fdump(w, pUntrusted) // NOT OK |
| 39 | + spew.Fprint(w, pUntrusted) // NOT OK |
| 40 | + spew.Fprintln(w, pUntrusted) // NOT OK |
| 41 | + spew.Fprintf(w, sUntrusted, p) // NOT OK |
| 42 | + spew.Fprintf(w, s, pUntrusted) // NOT OK |
| 43 | + |
| 44 | + str1 := spew.Sdump(pUntrusted) |
| 45 | + sinkString(str1) // NOT OK |
| 46 | + |
| 47 | + str2 := spew.Sprint(pUntrusted) |
| 48 | + sinkString(str2) // NOT OK |
| 49 | + |
| 50 | + str3 := spew.Sprintf(sUntrusted, p) |
| 51 | + sinkString(str3) // NOT OK |
| 52 | + |
| 53 | + str4 := spew.Sprintf(s, pUntrusted) |
| 54 | + sinkString(str4) // NOT OK |
| 55 | + |
| 56 | + str5 := spew.Sprintln(pUntrusted) |
| 57 | + sinkString(str5) // NOT OK |
| 58 | +} |
0 commit comments