[bug] Segfault on macOS when calling `rows.Close()` after selecting from nonexistent table.
Hi!
While working on a side project I stumbled around a segfault in this library. It only appears when I call the offending function from the one script, not from the other.
From the attached repro script, the bug seems to always be triggered.
Thanks for your work on this project and please let me know if I can help you.
repro.go:
package main
import (
"database/sql"
_ "modernc.org/sqlite"
"strings"
)
func handle(err error) {
if err != nil {
panic(err)
}
}
func main() {
db, err := sql.Open("sqlite", "test.db")
handle(err)
rows, err := db.Query("select * from nonexistant limit 1;")
if strings.Contains(err.Error(), "SQL logic error: no such table") {
println("no table")
} else {
println("table")
}
rows.Close()
}
$ go run repro.go
no table
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x10a284e]
goroutine 1 [running]:
database/sql.(*Rows).close(0x0, {0x0, 0x0})
/usr/local/Cellar/go/1.18/libexec/src/database/sql/sql.go:3308 +0x8e
database/sql.(*Rows).Close(...)
/usr/local/Cellar/go/1.18/libexec/src/database/sql/sql.go:3304
main.main()
/Users/casparfriedrich/Desktop/kvass/repro.go:25 +0xd9
exit status 2
go.mod: (haven't cleaned this up yet, sorry)
module github.com/maxmunzel/kvass
go 1.18
require (
github.com/google/uuid v1.3.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
github.com/teris-io/cli v1.0.1
golang.org/x/mod v0.3.0 // indirect
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac // indirect
golang.org/x/tools v0.0.0-20201124115921-2c860bdd6e78 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
lukechampine.com/uint128 v1.1.1 // indirect
modernc.org/cc/v3 v3.36.0 // indirect
modernc.org/ccgo/v3 v3.16.6 // indirect
modernc.org/libc v1.16.7 // indirect
modernc.org/mathutil v1.4.1 // indirect
modernc.org/memory v1.1.1 // indirect
modernc.org/opt v0.1.1 // indirect
modernc.org/sqlite v1.17.3
modernc.org/strutil v1.1.1 // indirect
modernc.org/token v1.0.0 // indirect
)
$ uname -a
Darwin littlebird 20.3.0 Darwin Kernel Version 20.3.0: Thu Jan 21 00:07:06 PST
2021; root:xnu-7195.81.3~1/RELEASE_X86_64 x86_64
