Skip to content

Commit 16175c1

Browse files
authored
Adds a fuzz target (#908)
* Adds a fuzz target * Fixes memory leak
1 parent 3cbdae7 commit 16175c1

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

_example/fuzz/fuzz_openexec.go

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package sqlite3_fuzz
2+
3+
import (
4+
"bytes"
5+
"database/sql"
6+
"io/ioutil"
7+
8+
_ "github.com/mattn/go-sqlite3"
9+
)
10+
11+
func FuzzOpenExec(data []byte) int {
12+
sep := bytes.IndexByte(data, 0)
13+
if sep <= 0 {
14+
return 0
15+
}
16+
err := ioutil.WriteFile("/tmp/fuzz.db", data[sep+1:], 0644)
17+
if err != nil {
18+
return 0
19+
}
20+
db, err := sql.Open("sqlite3", "/tmp/fuzz.db")
21+
if err != nil {
22+
return 0
23+
}
24+
defer db.Close()
25+
_, err = db.Exec(string(data[:sep-1]))
26+
if err != nil {
27+
return 0
28+
}
29+
return 1
30+
}

sqlite3.go

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

0 commit comments

Comments
 (0)