File tree Expand file tree Collapse file tree 3 files changed +65
-0
lines changed Expand file tree Collapse file tree 3 files changed +65
-0
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,12 @@ type sqlStatement struct {
3232}
3333
3434var sqlCallIdents = map [string ]map [string ]int {
35+ "*database/sql.Conn" : {
36+ "ExecContext" : 1 ,
37+ "QueryContext" : 1 ,
38+ "QueryRowContext" : 1 ,
39+ "PrepareContext" : 1 ,
40+ },
3541 "*database/sql.DB" : {
3642 "Exec" : 0 ,
3743 "ExecContext" : 1 ,
Original file line number Diff line number Diff line change @@ -103,6 +103,36 @@ func main(){
103103 panic(err)
104104 }
105105}
106+ ` }, 1 , gosec .NewConfig ()},
107+ {[]string {`
108+ // Format string without proper quoting with connection
109+ package main
110+ import (
111+ "context"
112+ "database/sql"
113+ "fmt"
114+ "os"
115+ )
116+
117+ func main(){
118+ db, err := sql.Open("sqlite3", ":memory:")
119+ if err != nil {
120+ panic(err)
121+ }
122+ conn, err := db.Conn(context.Background())
123+ if err != nil {
124+ panic(err)
125+ }
126+ q := fmt.Sprintf("select * from foo where name = '%s'", os.Args[1])
127+ rows, err := conn.QueryContext(context.Background(), q)
128+ if err != nil {
129+ panic(err)
130+ }
131+ defer rows.Close()
132+ if err := conn.Close(); err != nil {
133+ panic(err)
134+ }
135+ }
106136` }, 1 , gosec .NewConfig ()},
107137 {[]string {`
108138// Format string false positive, safe string spec.
Original file line number Diff line number Diff line change @@ -119,6 +119,35 @@ func main(){
119119 panic(err)
120120 }
121121}
122+ ` }, 1 , gosec .NewConfig ()},
123+ {[]string {`
124+ // DB connection check
125+ package main
126+
127+ import (
128+ "context"
129+ "database/sql"
130+ "os"
131+ )
132+
133+ func main(){
134+ db, err := sql.Open("sqlite3", ":memory:")
135+ if err != nil {
136+ panic(err)
137+ }
138+ conn, err := db.Conn(context.Background())
139+ if err != nil {
140+ panic(err)
141+ }
142+ rows, err := conn.QueryContext(context.Background(), "select * from foo where name = " + os.Args[1])
143+ if err != nil {
144+ panic(err)
145+ }
146+ defer rows.Close()
147+ if err := conn.Close(); err != nil {
148+ panic(err)
149+ }
150+ }
122151` }, 1 , gosec .NewConfig ()},
123152 {[]string {`
124153// multiple string concatenation
You can’t perform that action at this time.
0 commit comments