fix(sqlite): don't dereference a NULL declared type in column_nullable - #4374
Open
msdrigg wants to merge 1 commit into
Open
fix(sqlite): don't dereference a NULL declared type in column_nullable#4374msdrigg wants to merge 1 commit into
msdrigg wants to merge 1 commit into
Conversation
sqlite3_table_column_metadata() leaves its declared-type out-param NULL for a column declared without a type, e.g. `CREATE TABLE foo (bar PRIMARY KEY)`. column_nullable() passed that pointer straight to CStr::from_ptr(), so describing such a column segfaulted the process, and rustc itself, since the query!() macros describe a live database at expansion time. A column with no declared type is not declared INTEGER and so cannot be a rowid alias; treat it as a normal column and fall through to the NOT NULL flag. Regression introduced in 69ee0df (transact-rs#4088), released in 0.9.0.
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.
Fixes #4373
sqlite3_table_column_metadata()leaves its declared-type out-param NULL when a column was declared with no type (CREATE TABLE foo (bar PRIMARY KEY)is legal SQLite).column_nullable()passed that pointer straight intoCStr::from_ptr(), so describing such a column segfaulted. Sincequery!()describes a live database while expanding, the process that died wasrustc.Introduced in 69ee0df (#4088), released in 0.9.0. Before that the slot was
ptr::null_mut()and never read.The fix. Only read the pointer when it's non-null. A column with no declared type isn't declared
INTEGER, so it can't be a rowid alias, and it falls through to the ordinaryNOT NULLcheck:This matches what
column_decltype()right above already does with the pointer fromsqlite3_column_decltype().That's also the correct answer semantically, not just a crash guard: a
PRIMARY KEYwith no declared type has BLOB affinity, is not a rowid alias, and SQLite really does allow NULLs in it, soSome(true)is right.After the fix, an untyped column gives the normal diagnostic instead of a crash:
and a type override (
device_id as "device_id!: String") compiles cleanly. That's the behaviour #1979 and #3546 describe.