Repository navigation
Add Conn.SetDefensive, wrapping SQLITE_DBCONFIG_DEFENSIVE - #21
Open
louisabraham wants to merge 2 commits into
Open
louisabraham wants to merge 2 commits into
louisabraham wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
Conn.SetDefensive(enabled bool) error, which callssqlite3_db_config(db, SQLITE_DBCONFIG_DEFENSIVE, …)through the existingdb_config_onoffhelper.While the flag is on, SQL cannot deliberately corrupt the database file:
PRAGMA writable_schema=ON,PRAGMA journal_mode=OFF, writes tosqlite_dbpageand 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).SetDefensiveinzombiezen.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/sqliteto this package to get the C build of SQLite. Defensive mode is the only setting we use that has no equivalent here.Tests
TestSetDefensivecreates a table, setswritable_schema = ON, then writes tosqlite_schema. The write fails with the flag on and succeeds with it off. The test also fails ifSetDefensiveis changed to do nothing.go test ./...passes.CHANGELOG.mdhas an entry under Unreleased.