From 66601dd3cb657768bd39ad763527b6e83e4b20f8 Mon Sep 17 00:00:00 2001 From: Nuno Cruces Date: Thu, 19 Dec 2024 14:00:46 +0000 Subject: [PATCH] More BCE. --- ext/blobio/blob.go | 4 ++++ ext/regexp/regexp.go | 3 +++ ext/unicode/unicode.go | 1 + internal/util/mmap_unix.go | 10 +++++----- sqlite.go | 5 +++-- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/ext/blobio/blob.go b/ext/blobio/blob.go index be5bdba..1a3389d 100644 --- a/ext/blobio/blob.go +++ b/ext/blobio/blob.go @@ -44,6 +44,8 @@ func Register(db *sqlite3.Conn) error { type OpenCallback func(*sqlite3.Blob, ...sqlite3.Value) error func readblob(ctx sqlite3.Context, arg ...sqlite3.Value) { + _ = arg[5] // bounds check + blob, err := getAuxBlob(ctx, arg, false) if err != nil { ctx.ResultError(err) @@ -78,6 +80,8 @@ func readblob(ctx sqlite3.Context, arg ...sqlite3.Value) { } func writeblob(ctx sqlite3.Context, arg ...sqlite3.Value) { + _ = arg[5] // bounds check + blob, err := getAuxBlob(ctx, arg, true) if err != nil { ctx.ResultError(err) diff --git a/ext/regexp/regexp.go b/ext/regexp/regexp.go index 8a1867f..dca2f12 100644 --- a/ext/regexp/regexp.go +++ b/ext/regexp/regexp.go @@ -76,6 +76,7 @@ func load(ctx sqlite3.Context, i int, expr string) (*regexp.Regexp, error) { } func regex(ctx sqlite3.Context, arg ...sqlite3.Value) { + _ = arg[1] // bounds check re, err := load(ctx, 0, arg[0].Text()) if err != nil { ctx.ResultError(err) @@ -165,6 +166,8 @@ func regexInstr(ctx sqlite3.Context, arg ...sqlite3.Value) { } func regexReplace(ctx sqlite3.Context, arg ...sqlite3.Value) { + _ = arg[2] // bounds check + re, err := load(ctx, 1, arg[1].Text()) if err != nil { ctx.ResultError(err) diff --git a/ext/unicode/unicode.go b/ext/unicode/unicode.go index 31c22b5..52e9e92 100644 --- a/ext/unicode/unicode.go +++ b/ext/unicode/unicode.go @@ -189,6 +189,7 @@ func like(ctx sqlite3.Context, arg ...sqlite3.Value) { return } } + _ = arg[1] // bounds check type likeData struct { *regexp.Regexp diff --git a/internal/util/mmap_unix.go b/internal/util/mmap_unix.go index 5d5ca38..4ff0566 100644 --- a/internal/util/mmap_unix.go +++ b/internal/util/mmap_unix.go @@ -39,13 +39,13 @@ func (s *mmapState) new(ctx context.Context, mod api.Module, size int32) *Mapped // Save the newly allocated region. ptr := uint32(stack[0]) buf := View(mod, ptr, uint64(size)) - addr := unsafe.Pointer(&buf[0]) - s.regions = append(s.regions, &MappedRegion{ + res := &MappedRegion{ Ptr: ptr, - addr: addr, size: size, - }) - return s.regions[len(s.regions)-1] + addr: unsafe.Pointer(&buf[0]), + } + s.regions = append(s.regions, res) + return res } type MappedRegion struct { diff --git a/sqlite.go b/sqlite.go index 2afe997..18a2c2a 100644 --- a/sqlite.go +++ b/sqlite.go @@ -265,10 +265,11 @@ func (a *arena) mark() (reset func()) { ptrs := len(a.ptrs) next := a.next return func() { - for _, ptr := range a.ptrs[ptrs:] { + rest := a.ptrs[ptrs:] + for _, ptr := range a.ptrs[:ptrs] { a.sqlt.free(ptr) } - a.ptrs = a.ptrs[:ptrs] + a.ptrs = rest a.next = next } }