-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Rust: Add numeric type barriers for three queries #20740
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
aaa3b1b
Rust: Add a couple of new test cases.
geoffw0 47019f7
Rust: Define NumericType, IntegralType and FloatingPointType in Built…
geoffw0 6433bec
Rust: Add a test for BuiltinTypes.
geoffw0 52397f0
Rust: Add numeric type barrier for SQL injection.
geoffw0 2d4369a
Rust: Add numeric type barrier for log injection.
geoffw0 33efed9
Rust: Add integral type barrier for Regex injection.
geoffw0 34f7595
Rust: Change note.
geoffw0 8548c16
Rust: Autoformat.
geoffw0 c381153
Apply suggestions from code review
geoffw0 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 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /** | ||
| * Classes to represent barriers commonly used in dataflow and taint tracking | ||
| * configurations. | ||
| */ | ||
|
|
||
| import rust | ||
| private import codeql.rust.dataflow.DataFlow | ||
| private import codeql.rust.internal.TypeInference as TypeInference | ||
| private import codeql.rust.internal.Type | ||
| private import codeql.rust.frameworks.stdlib.Builtins | ||
|
|
||
| /** | ||
| * A node whose type is a numeric or boolean type, which may be an appropriate | ||
| * taint flow barrier for some queries. | ||
| */ | ||
| class NumericTypeBarrier extends DataFlow::Node { | ||
| NumericTypeBarrier() { | ||
| exists(TypeInference::Type t | | ||
| t = TypeInference::inferType(this.asExpr().getExpr()) and | ||
| ( | ||
| t.(StructType).getStruct() instanceof NumericType or | ||
| t.(StructType).getStruct() instanceof Bool | ||
| ) | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * A node whose type is an integral (integer) or boolean type, which may be an | ||
| * appropriate taint flow barrier for some queries. | ||
| */ | ||
| class IntegralOrBooleanTypeBarrier extends DataFlow::Node { | ||
| IntegralOrBooleanTypeBarrier() { | ||
| exists(TypeInference::Type t | | ||
| t = TypeInference::inferType(this.asExpr().getExpr()) and | ||
| ( | ||
| t.(StructType).getStruct() instanceof IntegralType or | ||
| t.(StructType).getStruct() instanceof Bool | ||
| ) | ||
| ) | ||
geoffw0 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| --- | ||
| category: minorAnalysis | ||
| --- | ||
| * Taint flow barriers have been added to the `rust/regex-injection`, `rust/sql-injection` and `rust/log-injection`, reducing the frequency of false positive results for these queries. |
17 changes: 17 additions & 0 deletions
17
rust/ql/test/library-tests/elements/builtintypes/BuiltinTypes.expected
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| | struct bool | | | ||
| | struct char | | | ||
| | struct f32 | FloatingPointType, NumericType | | ||
| | struct f64 | FloatingPointType, NumericType | | ||
| | struct i8 | IntegralType, NumericType | | ||
| | struct i16 | IntegralType, NumericType | | ||
| | struct i32 | IntegralType, NumericType | | ||
| | struct i64 | IntegralType, NumericType | | ||
| | struct i128 | IntegralType, NumericType | | ||
| | struct isize | IntegralType, NumericType | | ||
| | struct str | | | ||
| | struct u8 | IntegralType, NumericType | | ||
| | struct u16 | IntegralType, NumericType | | ||
| | struct u32 | IntegralType, NumericType | | ||
| | struct u64 | IntegralType, NumericType | | ||
| | struct u128 | IntegralType, NumericType | | ||
| | struct usize | IntegralType, NumericType | |
14 changes: 14 additions & 0 deletions
14
rust/ql/test/library-tests/elements/builtintypes/BuiltinTypes.ql
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import rust | ||
| import codeql.rust.frameworks.stdlib.Builtins | ||
| import codeql.rust.internal.Type | ||
|
|
||
| string describe(BuiltinType t) { | ||
| (t instanceof NumericType and result = "NumericType") | ||
| or | ||
| (t instanceof IntegralType and result = "IntegralType") | ||
| or | ||
| (t instanceof FloatingPointType and result = "FloatingPointType") | ||
| } | ||
|
|
||
| from BuiltinType t | ||
| select t.toString(), concat(describe(t), ", ") |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
|
|
||
| // --- tests --- | ||
|
|
||
| fn test_types() { | ||
| } |
1 change: 1 addition & 0 deletions
1
rust/ql/test/query-tests/security/CWE-020/RegexInjectionSink.expected
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| | main.rs:6:25:6:30 | ®ex | | ||
| | main.rs:14:25:14:30 | ®ex | | ||
| | main.rs:21:25:21:30 | ®ex | |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.