aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--_example/fuzz/fuzz_openexec.go30
-rw-r--r--sqlite3.go2
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
+}
diff --git a/sqlite3.go b/sqlite3.go
index 552a2ab..5ac9570 100644
--- a/sqlite3.go
+++ b/sqlite3.go
@@ -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
}