Skip to content

Commit ab9ab0e

Browse files
authored
Merge pull request github#18536 from GeekMasher/rust-postgres
Rust: Add Postgres crate Models
2 parents 7b071ba + 2b74061 commit ab9ab0e

File tree

7 files changed

+96
-3
lines changed

7 files changed

+96
-3
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
extensions:
2+
- addsTo:
3+
pack: codeql/rust-all
4+
extensible: sinkModel
5+
data:
6+
- ["repo:https://github.com/sfackler/rust-postgres:postgres", "<crate::client::Client>::execute", "Argument[0]", "sql-injection", "manual"]
7+
- ["repo:https://github.com/sfackler/rust-postgres:postgres", "<crate::client::Client>::batch_execute", "Argument[0]", "sql-injection", "manual"]
8+
- ["repo:https://github.com/sfackler/rust-postgres:postgres", "<crate::client::Client>::prepare", "Argument[0]", "sql-injection", "manual"]
9+
- ["repo:https://github.com/sfackler/rust-postgres:postgres", "<crate::client::Client>::prepare_typed", "Argument[0]", "sql-injection", "manual"]
10+
- ["repo:https://github.com/sfackler/rust-postgres:postgres", "<crate::client::Client>::query", "Argument[0]", "sql-injection", "manual"]
11+
- ["repo:https://github.com/sfackler/rust-postgres:postgres", "<crate::client::Client>::query_one", "Argument[0]", "sql-injection", "manual"]
12+
- ["repo:https://github.com/sfackler/rust-postgres:postgres", "<crate::client::Client>::query_opt", "Argument[0]", "sql-injection", "manual"]
13+
- ["repo:https://github.com/sfackler/rust-postgres:postgres", "<crate::client::Client>::query_raw", "Argument[0]", "sql-injection", "manual"]
14+
- ["repo:https://github.com/sfackler/rust-postgres:postgres", "<crate::client::Client>::query_typed", "Argument[0]", "sql-injection", "manual"]
15+
- ["repo:https://github.com/sfackler/rust-postgres:postgres", "<crate::client::Client>::query_typed_raw", "Argument[0]", "sql-injection", "manual"]

rust/ql/test/library-tests/dataflow/taint/TaintFlowStep.expected

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
| file://:0:0:0:0 | [summary param] 0 in lang:alloc::_::crate::fmt::format | file://:0:0:0:0 | [summary] to write: ReturnValue in lang:alloc::_::crate::fmt::format | MaD:14 |
2-
| file://:0:0:0:0 | [summary param] self in lang:alloc::_::<crate::string::String>::as_str | file://:0:0:0:0 | [summary] to write: ReturnValue in lang:alloc::_::<crate::string::String>::as_str | MaD:12 |
3-
| file://:0:0:0:0 | [summary param] self in repo:https://github.com/seanmonstar/reqwest:reqwest::_::<crate::blocking::response::Response>::text | file://:0:0:0:0 | [summary] to write: ReturnValue.Variant[crate::result::Result::Ok(0)] in repo:https://github.com/seanmonstar/reqwest:reqwest::_::<crate::blocking::response::Response>::text | MaD:0 |
1+
| file://:0:0:0:0 | [summary param] 0 in lang:alloc::_::crate::fmt::format | file://:0:0:0:0 | [summary] to write: ReturnValue in lang:alloc::_::crate::fmt::format | MaD:24 |
2+
| file://:0:0:0:0 | [summary param] self in lang:alloc::_::<crate::string::String>::as_str | file://:0:0:0:0 | [summary] to write: ReturnValue in lang:alloc::_::<crate::string::String>::as_str | MaD:22 |
3+
| file://:0:0:0:0 | [summary param] self in repo:https://github.com/seanmonstar/reqwest:reqwest::_::<crate::blocking::response::Response>::text | file://:0:0:0:0 | [summary] to write: ReturnValue.Variant[crate::result::Result::Ok(0)] in repo:https://github.com/seanmonstar/reqwest:reqwest::_::<crate::blocking::response::Response>::text | MaD:10 |
44
| main.rs:4:5:4:8 | 1000 | main.rs:4:5:4:12 | ... + ... | |
55
| main.rs:4:12:4:12 | i | main.rs:4:5:4:12 | ... + ... | |
66
| main.rs:8:20:8:20 | s | main.rs:8:14:8:20 | FormatArgsExpr | |

rust/ql/test/library-tests/frameworks/postgres/Postgres.expected

Whitespace-only changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import rust
2+
import codeql.rust.security.SqlInjectionExtensions
3+
import utils.test.InlineExpectationsTest
4+
5+
module PostgresTest implements TestSig {
6+
string getARelevantTag() { result = "sql-sink" }
7+
8+
predicate hasActualResult(Location location, string element, string tag, string value) {
9+
exists(SqlInjection::Sink sink |
10+
location = sink.getLocation() and
11+
location.getFile().getBaseName() != "" and
12+
element = sink.toString() and
13+
tag = "sql-sink" and
14+
value = ""
15+
)
16+
}
17+
}
18+
19+
import MakeTest<PostgresTest>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[workspace]
2+
3+
[package]
4+
name = "postgres-test"
5+
version = "0.1.0"
6+
edition = "2021"
7+
8+
[dependencies]
9+
postgres = { version = "0.19" }
10+
11+
[[bin]]
12+
name = "postgres"
13+
path = "./main.rs"
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
3+
fn main() -> Result<(), Box<dyn std::error::Error>> {
4+
// Get input from CLI
5+
let args: Vec<String> = std::env::args().collect();
6+
let name = &args[1];
7+
let age = &args[2];
8+
9+
let mut conn = postgres::Client::connect("host=localhost user=postgres", postgres::NoTls)?;
10+
11+
conn.execute( // $ sql-sink
12+
"CREATE TABLE person (
13+
id SERIAL PRIMARY KEY,
14+
name VARCHAR NOT NULL,
15+
age INT NOT NULL
16+
)",
17+
&[],
18+
)?;
19+
20+
let query = format!("INSERT INTO person (name, age) VALUES ('{}', '{}')", name, age);
21+
22+
conn.execute(query.as_str(), &[])?; // $ sql-sink
23+
conn.batch_execute(query.as_str())?; // $ sql-sink
24+
25+
conn.prepare(query.as_str())?; // $ sql-sink
26+
// conn.prepare_typed(query.as_str(), &[])?;
27+
28+
conn.query(query.as_str(), &[])?; // $ sql-sink
29+
conn.query_one(query.as_str(), &[])?; // $ sql-sink
30+
conn.query_opt(query.as_str(), &[])?; // $ sql-sink
31+
// conn.query_raw(query.as_str(), &[])?;
32+
// conn.query_typed(query.as_str(), &[])?;
33+
// conn.query_typed_raw(query.as_str(), &[])?;
34+
35+
for row in &conn.query("SELECT id, name, age FROM person", &[])? { // $ sql-sink
36+
let id: i32 = row.get("id");
37+
let name: &str = row.get("name");
38+
let age: i32 = row.get("age");
39+
println!("found person: {} {} {}", id, name, age);
40+
}
41+
42+
Ok(())
43+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
qltest_cargo_check: true
2+
qltest_dependencies:
3+
- postgres = { version = "0.19" }

0 commit comments

Comments
 (0)