Adds a fuzz target (#908)

* Adds a fuzz target

* Fixes memory leak
This commit is contained in:
Catena cyber 2021-02-15 14:57:26 +01:00 committed by GitHub
parent 3cbdae750e
commit 16175c1389
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 1 deletions

View File

@ -0,0 +1,30 @@
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
}

View File

@ -1676,7 +1676,7 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
//
// Because default is NORMAL this statement is always executed
if err := exec(fmt.Sprintf("PRAGMA synchronous = %s;", synchronousMode)); err != nil {
C.sqlite3_close_v2(db)
conn.Close()
return nil, err
}