File: fuzz_openexec.go

package info (click to toggle)
golang-github-mattn-go-sqlite3 1.14.16~ds1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bookworm-backports
  • size: 768 kB
  • sloc: cpp: 1,132; ansic: 712; makefile: 60
file content (30 lines) | stat: -rw-r--r-- 477 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
}