-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18405 from egregius313/egregius313/go/mad/databas…
…e/gorm Go: Model sources from the `gorm.io/gorm` package
- Loading branch information
Showing
7 changed files
with
178 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
category: minorAnalysis | ||
--- | ||
* Added `database` source models for database methods from the `gorm.io/gorm` package. | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
go/ql/test/library-tests/semmle/go/dataflow/flowsources/local/database/go.mod
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module test | ||
|
||
go 1.22.5 | ||
|
||
require ( | ||
gorm.io/gorm v1.23.0 | ||
) |
59 changes: 59 additions & 0 deletions
59
go/ql/test/library-tests/semmle/go/dataflow/flowsources/local/database/test_gorm.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package test | ||
|
||
import "gorm.io/gorm" | ||
|
||
// test querying an Association | ||
func test_gorm_AssociationQuery(association *gorm.Association) { | ||
association.Find(&User{}) // $ source | ||
} | ||
|
||
// test querying a ConnPool | ||
func test_gorm_ConnPoolQuery(connPool gorm.ConnPool) { | ||
rows, err := connPool.QueryContext(nil, "SELECT * FROM users") // $ source | ||
|
||
if err != nil { | ||
return | ||
} | ||
|
||
defer rows.Close() | ||
|
||
userRow := connPool.QueryRowContext(nil, "SELECT * FROM users WHERE id = 1") // $ source | ||
|
||
ignore(userRow) | ||
} | ||
|
||
// test querying a DB | ||
func test_gorm_db(db *gorm.DB) { | ||
db.Find(&User{}) // $ source | ||
|
||
db.FindInBatches(&User{}, 10, nil) // $ source | ||
|
||
db.FirstOrCreate(&User{}) // $ source | ||
|
||
db.FirstOrInit(&User{}) // $ source | ||
|
||
db.First(&User{}) // $ source | ||
|
||
db.Last(&User{}) // $ source | ||
|
||
db.Take(&User{}) // $ source | ||
|
||
db.Scan(&User{}) // $ source | ||
|
||
var user User | ||
db.Model(&user) // $ source | ||
|
||
row := db.Row() // $ source | ||
ignore(row) | ||
|
||
rows, err := db.Rows() // $ source | ||
ignore(err) | ||
|
||
var user2 User | ||
db.ScanRows(rows, &user2) | ||
|
||
sink(user2) // $ hasTaintFlow="user2" | ||
|
||
var names []string | ||
db.Pluck("name", &names) // $ source | ||
} |
3 changes: 3 additions & 0 deletions
3
go/ql/test/library-tests/semmle/go/dataflow/flowsources/local/database/user.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package test | ||
|
||
type User struct{} |
77 changes: 77 additions & 0 deletions
77
...t/library-tests/semmle/go/dataflow/flowsources/local/database/vendor/gorm.io/gorm/stub.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
go/ql/test/library-tests/semmle/go/dataflow/flowsources/local/database/vendor/modules.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# gorm.io/gorm v1.23.0 | ||
## explicit | ||
gorm.io/gorm |