0
0
mirror of https://github.com/mattn/go-sqlite3.git synced 2024-11-07 05:18:43 +00:00
go-sqlite3/_example/fuzz/fuzz_openexec.go
Catena cyber 16175c1389
Adds a fuzz target (#908)
* Adds a fuzz target

* Fixes memory leak
2021-02-15 22:57:26 +09:00

31 lines
477 B
Go

package sqlite3_fuzz
import (
"bytes"
"database/sql"
"io/ioutil"
_ "github.com/mattn/go-sqlite3"
)
func FuzzOpenExec(data []byte) int {
sep := bytes.IndexByte(data, 0)
if sep <= 0 {
return 0
}
err := ioutil.WriteFile("/tmp/fuzz.db", data[sep+1:], 0644)
if err != nil {
return 0
}
db, err := sql.Open("sqlite3", "/tmp/fuzz.db")
if err != nil {
return 0
}
defer db.Close()
_, err = db.Exec(string(data[:sep-1]))
if err != nil {
return 0
}
return 1
}