diff options
author | Catena cyber <35799796+catenacyber@users.noreply.github.com> | 2021-02-15 14:57:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-15 22:57:26 +0900 |
commit | 16175c13894d954d85d3d5d271c2677289a788b9 (patch) | |
tree | 4bdb44033e2458110fb4207c09a2274c41076e79 | |
parent | Export sqlite3_stmt_readonly() via SQLiteStmt.Readonly() (#895) (diff) | |
download | golite-16175c13894d954d85d3d5d271c2677289a788b9.tar.gz golite-16175c13894d954d85d3d5d271c2677289a788b9.tar.xz |
Adds a fuzz target (#908)
* Adds a fuzz target
* Fixes memory leak
-rw-r--r-- | _example/fuzz/fuzz_openexec.go | 30 | ||||
-rw-r--r-- | sqlite3.go | 2 |
2 files changed, 31 insertions, 1 deletions
diff --git a/_example/fuzz/fuzz_openexec.go b/_example/fuzz/fuzz_openexec.go new file mode 100644 index 0000000..5326044 --- /dev/null +++ b/_example/fuzz/fuzz_openexec.go @@ -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 +} @@ -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 } |