-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Rust: Add initial RuSQLite support #18577
Open
GeekMasher
wants to merge
4
commits into
github:main
Choose a base branch
from
GeekMasher:rust-rusqlite
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e205a68
feat(rust:) Add initial rusqlite support
GeekMasher eac63a3
fix(rust): Update TaintFlowStep
GeekMasher c69bb15
Update rust/ql/test/library-tests/frameworks/rusqlite/main.rs
GeekMasher 788ae2a
Merge branch 'main' into rust-rusqlite
GeekMasher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
extensions: | ||
- addsTo: | ||
pack: codeql/rust-all | ||
extensible: sinkModel | ||
data: | ||
- ["repo:https://github.com/rusqlite/rusqlite:rusqlite", "<crate::Connection>::execute", "Argument[0]", "sql-injection", "manual"] | ||
- ["repo:https://github.com/rusqlite/rusqlite:rusqlite", "<crate::Connection>::execute_batch", "Argument[0]", "sql-injection", "manual"] | ||
- ["repo:https://github.com/rusqlite/rusqlite:rusqlite", "<crate::Connection>::prepare", "Argument[0]", "sql-injection", "manual"] | ||
- ["repo:https://github.com/rusqlite/rusqlite:rusqlite", "<crate::Connection>::prepare_with_flags", "Argument[0]", "sql-injection", "manual"] | ||
- ["repo:https://github.com/rusqlite/rusqlite:rusqlite", "<crate::Connection>::query_row", "Argument[0]", "sql-injection", "manual"] | ||
- ["repo:https://github.com/rusqlite/rusqlite:rusqlite", "<crate::Connection>::query_row_and_then", "Argument[0]", "sql-injection", "manual"] |
6 changes: 3 additions & 3 deletions
6
rust/ql/test/library-tests/dataflow/taint/TaintFlowStep.expected
This file contains 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
Empty file.
20 changes: 20 additions & 0 deletions
20
rust/ql/test/library-tests/frameworks/rusqlite/Rusqlite.ql
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import rust | ||
import codeql.rust.security.SqlInjectionExtensions | ||
import codeql.rust.Concepts | ||
import utils.test.InlineExpectationsTest | ||
|
||
module RusqliteTest implements TestSig { | ||
string getARelevantTag() { result = ["sql-sink"] } | ||
|
||
predicate hasActualResult(Location location, string element, string tag, string value) { | ||
exists(SqlInjection::Sink sink | | ||
location = sink.getLocation() and | ||
location.getFile().getBaseName() != "" and | ||
element = sink.toString() and | ||
tag = "sql-sink" and | ||
value = "" | ||
) | ||
} | ||
} | ||
|
||
import MakeTest<RusqliteTest> |
13 changes: 13 additions & 0 deletions
13
rust/ql/test/library-tests/frameworks/rusqlite/cargo.toml.manual
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[workspace] | ||
|
||
[package] | ||
name = "rusqlite-test" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
rusqlite = { version = "0.33", features = ["bundled"] } | ||
|
||
[[bin]] | ||
name = "rusqlite" | ||
path = "./main.rs" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
|
||
use rusqlite::Connection; | ||
|
||
#[derive(Debug)] | ||
struct Person { | ||
id: i32, | ||
name: String, | ||
age: i32, | ||
} | ||
|
||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
// Get input from CLI | ||
let args: Vec<String> = std::env::args().collect(); | ||
let name = &args[1]; | ||
let age = &args[2]; | ||
|
||
let connection = Connection::open_in_memory()?; | ||
|
||
connection.execute( // $ sql-sink | ||
"CREATE TABLE person ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
name VARCHAR NOT NULL, | ||
age INT NOT NULL | ||
)", | ||
(), | ||
)?; | ||
|
||
let query = format!("INSERT INTO person (name, age) VALUES ('{}', '{}')", name, age); | ||
|
||
connection.execute(&query, ())?; // $ sql-sink | ||
|
||
let person = connection.query_row(&query, (), |row| { // $ sql-sink | ||
Ok(Person { | ||
id: row.get(0)?, | ||
name: row.get(1)?, | ||
age: row.get(2)?, | ||
}) | ||
})?; | ||
|
||
let mut stmt = connection.prepare("SELECT id, name, age FROM person")?; // $ sql-sink | ||
let people = stmt.query_map([], |row| { | ||
Ok(Person { | ||
id: row.get(0)?, | ||
name: row.get(1)?, | ||
age: row.get(2)?, | ||
}) | ||
})?; | ||
|
||
Ok(()) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
qltest_cargo_check: true | ||
qltest_dependencies: | ||
- rusqlite = { version = "0.33", features = ["bundled"] } |
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.
Check warning
Code scanning / CodeQL
Singleton set literal Warning test