Skip to content

Commit f173305

Browse files
committed
Add tests for %T (passing but marked SPURIOUS)
1 parent 37aa479 commit f173305

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

go/ql/test/library-tests/semmle/go/concepts/LoggerCall/glog.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ func glogTest() {
3030
glog.Warningf(fmt, text) // $ logger=fmt logger=text
3131
glog.Warningln(text) // $ logger=text
3232

33+
// components corresponding to the format specifier "%T" are not considered vulnerable
34+
glog.Errorf("%s: found type %T", text, v) // $ logger="%s: found type %T" logger=text SPURIOUS: logger=v
35+
glog.Exitf("%s: found type %T", text, v) // $ logger="%s: found type %T" logger=text SPURIOUS: logger=v
36+
glog.Fatalf("%s: found type %T", text, v) // $ logger="%s: found type %T" logger=text SPURIOUS: logger=v
37+
glog.Infof("%s: found type %T", text, v) // $ logger="%s: found type %T" logger=text SPURIOUS: logger=v
38+
glog.Warningf("%s: found type %T", text, v) // $ logger="%s: found type %T" logger=text SPURIOUS: logger=v
39+
3340
klog.Error(text) // $ logger=text
3441
klog.ErrorDepth(0, text) // $ logger=text
3542
klog.Errorf(fmt, text) // $ logger=fmt logger=text
@@ -50,4 +57,11 @@ func glogTest() {
5057
klog.WarningDepth(0, text) // $ logger=text
5158
klog.Warningf(fmt, text) // $ logger=fmt logger=text
5259
klog.Warningln(text) // $ logger=text
60+
61+
// components corresponding to the format specifier "%T" are not considered vulnerable
62+
klog.Errorf("%s: found type %T", text, v) // $ logger="%s: found type %T" logger=text SPURIOUS: logger=v
63+
klog.Exitf("%s: found type %T", text, v) // $ logger="%s: found type %T" logger=text SPURIOUS: logger=v
64+
klog.Fatalf("%s: found type %T", text, v) // $ logger="%s: found type %T" logger=text SPURIOUS: logger=v
65+
klog.Infof("%s: found type %T", text, v) // $ logger="%s: found type %T" logger=text SPURIOUS: logger=v
66+
klog.Warningf("%s: found type %T", text, v) // $ logger="%s: found type %T" logger=text SPURIOUS: logger=v
5367
}

go/ql/test/library-tests/semmle/go/concepts/LoggerCall/logrus.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,8 @@ func logrusCalls() {
3232
logrus.Panicln(text) // $ logger=text
3333
logrus.Infof(fmt, text) // $ logger=fmt logger=text
3434
logrus.FatalFn(fn) // $ logger=fn
35+
36+
// components corresponding to the format specifier "%T" are not considered vulnerable
37+
logrus.Infof("%s: found type %T", text, v) // $ logger="%s: found type %T" logger=text SPURIOUS: logger=v
38+
logrus.Fatalf("%s: found type %T", text, v) // $ logger="%s: found type %T" logger=text SPURIOUS: logger=v
3539
}

go/ql/test/library-tests/semmle/go/concepts/LoggerCall/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package main
33
const fmt = "formatted %s string"
44
const text = "test"
55

6-
func main() {
6+
var v []byte
77

8+
func main() {
9+
stdlib()
810
}

go/ql/test/library-tests/semmle/go/concepts/LoggerCall/stdlib.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ func stdlib() {
1717
logger.Printf(fmt, text) // $ logger=fmt logger=text
1818
logger.Println(text) // $ logger=text
1919

20+
// components corresponding to the format specifier "%T" are not considered vulnerable
21+
logger.Fatalf("%s: found type %T", text, v) // $ logger="%s: found type %T" logger=text SPURIOUS: logger=v
22+
logger.Panicf("%s: found type %T", text, v) // $ logger="%s: found type %T" logger=text SPURIOUS: logger=v
23+
logger.Printf("%s: found type %T", text, v) // $ logger="%s: found type %T" logger=text SPURIOUS: logger=v
24+
2025
log.SetPrefix("prefix: ")
2126
log.Fatal(text) // $ logger=text
2227
log.Fatalf(fmt, text) // $ logger=fmt logger=text
@@ -27,4 +32,9 @@ func stdlib() {
2732
log.Print(text) // $ logger=text
2833
log.Printf(fmt, text) // $ logger=fmt logger=text
2934
log.Println(text) // $ logger=text
35+
36+
// components corresponding to the format specifier "%T" are not considered vulnerable
37+
log.Fatalf("%s: found type %T", text, v) // $ logger="%s: found type %T" logger=text SPURIOUS: logger=v
38+
log.Panicf("%s: found type %T", text, v) // $ logger="%s: found type %T" logger=text SPURIOUS: logger=v
39+
log.Printf("%s: found type %T", text, v) // $ logger="%s: found type %T" logger=text SPURIOUS: logger=v
3040
}

0 commit comments

Comments
 (0)