Skip to content

Add Conn.SetDefensive, wrapping SQLITE_DBCONFIG_DEFENSIVE - #21

Open
louisabraham wants to merge 2 commits into
go-llsqlite:masterfrom
conception-ai:set-defensive
Open

louisabraham wants to merge 2 commits into
go-llsqlite:masterfrom
conception-ai:set-defensive

Conversation

@louisabraham

Copy link
Copy Markdown

Adds Conn.SetDefensive(enabled bool) error, which calls sqlite3_db_config(db, SQLITE_DBCONFIG_DEFENSIVE, …) through the existing db_config_onoff helper.

While the flag is on, SQL cannot deliberately corrupt the database file: PRAGMA writable_schema=ON, PRAGMA journal_mode=OFF, writes to sqlite_dbpage and direct writes to shadow tables are turned off. See https://www.sqlite.org/c3ref/c_dbconfig_defensive.html#sqlitedbconfigdefensive.

The name and signature are the same as (*sqlite.Conn).SetDefensive in zombiezen.com/go/sqlite, so code written against that package keeps building here.

Context: we run untrusted SQL in a sandboxed service and are moving it from zombiezen.com/go/sqlite to this package to get the C build of SQLite. Defensive mode is the only setting we use that has no equivalent here.

Tests

  • TestSetDefensive creates a table, sets writable_schema = ON, then writes to sqlite_schema. The write fails with the flag on and succeeds with it off. The test also fails if SetDefensive is changed to do nothing.
  • go test ./... passes.
  • CHANGELOG.md has an entry under Unreleased.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant