Skip to content

Commit

Permalink
Adds a fuzz target (mattn#908)
Browse files Browse the repository at this point in the history
* Adds a fuzz target

* Fixes memory leak
  • Loading branch information
catenacyber authored Feb 15, 2021
1 parent 3cbdae7 commit 16175c1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
30 changes: 30 additions & 0 deletions _example/fuzz/fuzz_openexec.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion sqlite3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 16175c1

Please sign in to comment.