- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix a potential null pointer deref in the Sqlite backend #4224
Conversation
cc @diesel-rs/core I would like to release that as patch release somewhen this week. |
diesel/src/sqlite/connection/stmt.rs
Outdated
crate::result::EmptyQuery, | ||
))); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add a check after the call to sqlite3_prepare_v3()
to ensure that stmt
is not null before calling NonNull::new_unchecked()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the documentation of sqlite3_prepare_v3
that shouldn't be necessary as we already cover both variants that are documented to return null. That written: It might still be worth to add that additional check to be sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The above check is not enough, since the pointer will be null if the query string is not empty but contains only whitespaces or comments. We should also add a test for this.
It looks like that doesn't guard against strings that are considered empty by sqlite, e.g. whitespace and comments-only. |
Yes, but it should be done only if the call returned |
The documentation of `sqlite3_prepare_v3` states that: > *ppStmt is left pointing to a compiled prepared statement that can be executed using sqlite3_step(). If there is an error, *ppStmt is set to NULL. If the input text contains no SQL (if the input is an empty string or a comment) then *ppStmt is set to NULL. The calling procedure is responsible for deleting the compiled SQL statement using sqlite3_finalize() after it has finished with it. ppStmt may not be NULL. We already guard against the error case there before constructing the `NonNull` pointer, we do not guard against empty statements yet. This commit fixes that particular issue + adds a test to check if the fix works as expected. This fixes diesel-rs#4223
You are both correct, I misread that statment as literal empty string. Note to myself: Don't fix this kind of issues just before needing to leave. I've now pushed a fixed version by using |
Fix a potential null pointer deref in the Sqlite backend
The documentation of
sqlite3_prepare_v3
states that:We already guard against the error case there before constructing the
NonNull
pointer, we do not guard against empty statements yet. This commit fixes that particular issue + adds a test to check if the fix works as expected.This fixes #4223