Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +0,0 @@
| main.rs:34:37:34:54 | //... | Missing result: database-read |
| main.rs:35:37:35:54 | //... | Missing result: database-read |
| main.rs:36:37:36:54 | //... | Missing result: database-read |
| main.rs:43:41:43:58 | //... | Missing result: database-read |
| main.rs:44:41:44:58 | //... | Missing result: database-read |
| main.rs:45:41:45:58 | //... | Missing result: database-read |
16 changes: 8 additions & 8 deletions rust/ql/test/library-tests/frameworks/rusqlite/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,27 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
)",
(),
)?;

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 {
Comment thread
geoffw0 marked this conversation as resolved.
id: row.get(0)?, // $ database-read
name: row.get(1)?, // $ database-read
age: row.get(2)?, // $ database-read
id: row.get(0)?, // $ MISSING: database-read
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure the problem is a missing canonical path, or is the problem that getStaticTarget fails (due to type inferencer problem)?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checked the canonical path exists, the problem is the type inferencer, most likely the closure argument.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep you're right, the getStaticTarget fails (and thus getStaticTarget().(Addressable).getCanonicalPath() fails too) so it's likely a type inference problem.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's why I use a concat in my test predicate:

predicate test(MethodCallExpr e, Function target, string path) {
  target = e.getStaticTarget() and
  path = concat(target.getCanonicalPath())
}
  • no result means getStaticTarget() failed
  • empty string means: a target was found, but getCanonicalPath() failed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

most likely the closure argument.

Correct; type inference for closures is a known gap.

Yeah that's why I use a concat in my test predicate:

I can also recommend the various debug predicates in TypeInference.qll; change getRelevantLocatable to the relevant file+line, and then quick-eval debugInferType et al.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will try the TypeInference.qll debug predicates, thanks for reminding me those exist.

name: row.get(1)?, // $ MISSING: database-read
age: row.get(2)?, // $ MISSING: database-read
})
})?;

let mut stmt = connection.prepare("SELECT id, name, age FROM person")?; // $ sql-sink
let people = stmt.query_map([], |row| {
Ok(Person {
Comment thread
geoffw0 marked this conversation as resolved.
id: row.get_unwrap(0), // $ database-read
name: row.get_unwrap(1), // $ database-read
age: row.get_unwrap(2), // $ database-read
id: row.get_unwrap(0), // $ MISSING: database-read
name: row.get_unwrap(1), // $ MISSING: database-read
age: row.get_unwrap(2), // $ MISSING: database-read
})
})?;

Ok(())
}
}