Merge branch 'main' into rust-data-flow-models

This commit is contained in:
Simon Friis Vindum
2024-12-17 13:12:32 +01:00
719 changed files with 2304 additions and 1548 deletions

View File

@@ -105,7 +105,7 @@ RestPat/gen_rest_pat.rs e762bf7537225f97da751c5dca6a2cd3836ad7579b68c748b8c6cba6
RetTypeRepr/gen_ret_type_repr.rs 25edbd60ad63ab4266f6426ef50f1dd17e24132f5a24404d240a3f07daef6a31 25edbd60ad63ab4266f6426ef50f1dd17e24132f5a24404d240a3f07daef6a31
ReturnExpr/gen_return_expr.rs 4f6ef29d7b3c60d6d71d1a6034a0721671f517428ba21897361a92b01009d38f 4f6ef29d7b3c60d6d71d1a6034a0721671f517428ba21897361a92b01009d38f
ReturnTypeSyntax/gen_return_type_syntax.rs 0b11a4cc400f9a2001996f99d61391bdb636e8aea036f587cf18ad6a957fe496 0b11a4cc400f9a2001996f99d61391bdb636e8aea036f587cf18ad6a957fe496
SelfParam/gen_self_param.rs 9be528c454e2734292d54550f8850ae8e48e1558da46dcf7f06fc7a7a8c3e569 9be528c454e2734292d54550f8850ae8e48e1558da46dcf7f06fc7a7a8c3e569
SelfParam/gen_self_param.rs 15491f86a32020c9ed3ecadc08c945ed01916b63683f95d2f5c1bedb4f3f01f2 15491f86a32020c9ed3ecadc08c945ed01916b63683f95d2f5c1bedb4f3f01f2
SlicePat/gen_slice_pat.rs df4a6692f5100aa11dd777561400ce71e37b85f2363b0638c21975a1771b15d5 df4a6692f5100aa11dd777561400ce71e37b85f2363b0638c21975a1771b15d5
SliceTypeRepr/gen_slice_type_repr.rs e50c142b7cf7bc3040ad64f351488557323d0b2fd5d004b41ed0fa8e522b5648 e50c142b7cf7bc3040ad64f351488557323d0b2fd5d004b41ed0fa8e522b5648
SourceFile/gen_source_file.rs a7a1d4fa77b53adb6fbc031bf7ab49cf7c8787728ba0a687c348b5eefbb5b9df a7a1d4fa77b53adb6fbc031bf7ab49cf7c8787728ba0a687c348b5eefbb5b9df

View File

@@ -1 +1,5 @@
| gen_self_param.rs:5:13:5:21 | SelfParam | getNumberOfAttrs: | 0 | hasTypeRepr: | no | isMut: | yes | hasLifetime: | no | hasName: | yes |
| gen_self_param.rs:6:10:6:14 | SelfParam | getNumberOfAttrs: | 0 | hasTypeRepr: | no | isRef: | yes | isMut: | no | hasLifetime: | no | hasName: | yes |
| gen_self_param.rs:7:10:7:18 | SelfParam | getNumberOfAttrs: | 0 | hasTypeRepr: | no | isRef: | yes | isMut: | yes | hasLifetime: | no | hasName: | yes |
| gen_self_param.rs:8:12:8:15 | SelfParam | getNumberOfAttrs: | 0 | hasTypeRepr: | no | isRef: | no | isMut: | no | hasLifetime: | no | hasName: | yes |
| gen_self_param.rs:9:11:9:18 | SelfParam | getNumberOfAttrs: | 0 | hasTypeRepr: | no | isRef: | no | isMut: | yes | hasLifetime: | no | hasName: | yes |
| gen_self_param.rs:10:15:10:22 | SelfParam | getNumberOfAttrs: | 0 | hasTypeRepr: | no | isRef: | yes | isMut: | no | hasLifetime: | yes | hasName: | yes |

View File

@@ -3,15 +3,16 @@ import codeql.rust.elements
import TestUtils
from
SelfParam x, int getNumberOfAttrs, string hasTypeRepr, string isMut, string hasLifetime,
string hasName
SelfParam x, int getNumberOfAttrs, string hasTypeRepr, string isRef, string isMut,
string hasLifetime, string hasName
where
toBeTested(x) and
not x.isUnknown() and
getNumberOfAttrs = x.getNumberOfAttrs() and
(if x.hasTypeRepr() then hasTypeRepr = "yes" else hasTypeRepr = "no") and
(if x.isRef() then isRef = "yes" else isRef = "no") and
(if x.isMut() then isMut = "yes" else isMut = "no") and
(if x.hasLifetime() then hasLifetime = "yes" else hasLifetime = "no") and
if x.hasName() then hasName = "yes" else hasName = "no"
select x, "getNumberOfAttrs:", getNumberOfAttrs, "hasTypeRepr:", hasTypeRepr, "isMut:", isMut,
"hasLifetime:", hasLifetime, "hasName:", hasName
select x, "getNumberOfAttrs:", getNumberOfAttrs, "hasTypeRepr:", hasTypeRepr, "isRef:", isRef,
"isMut:", isMut, "hasLifetime:", hasLifetime, "hasName:", hasName

View File

@@ -0,0 +1 @@
| gen_self_param.rs:10:15:10:22 | SelfParam | gen_self_param.rs:10:16:10:17 | ''a |

View File

@@ -1 +1,5 @@
| gen_self_param.rs:5:13:5:21 | SelfParam | gen_self_param.rs:5:18:5:21 | self |
| gen_self_param.rs:6:10:6:14 | SelfParam | gen_self_param.rs:6:11:6:14 | self |
| gen_self_param.rs:7:10:7:18 | SelfParam | gen_self_param.rs:7:15:7:18 | self |
| gen_self_param.rs:8:12:8:15 | SelfParam | gen_self_param.rs:8:12:8:15 | self |
| gen_self_param.rs:9:11:9:18 | SelfParam | gen_self_param.rs:9:15:9:18 | self |
| gen_self_param.rs:10:15:10:22 | SelfParam | gen_self_param.rs:10:19:10:22 | self |

View File

@@ -1,8 +1,11 @@
// generated by codegen, do not edit
fn test_self_param() -> () {
// A `self` parameter. For example `self` in:
fn push(&mut self, value: T) {
// ...
}
// A `self` parameter. For example `self` in:
struct X;
impl X {
fn one(&self) {}
fn two(&mut self) {}
fn three(self) {}
fn four(mut self) {}
fn five<'a>(&'a self) {}
}

View File

@@ -3,7 +3,7 @@
*/
import rust
import utils.InlineFlowTest
import utils.test.InlineFlowTest
import DefaultFlowTest
import ValueFlow::PathGraph

View File

@@ -3,7 +3,7 @@
*/
import rust
import utils.InlineFlowTest
import utils.test.InlineFlowTest
import DefaultFlowTest
import ValueFlow::PathGraph

View File

@@ -3,7 +3,7 @@
*/
import rust
import utils.InlineFlowTest
import utils.test.InlineFlowTest
import DefaultFlowTest
import ValueFlow::PathGraph

View File

@@ -3,7 +3,7 @@
*/
import rust
import utils.InlineFlowTest
import utils.test.InlineFlowTest
import DefaultFlowTest
import ValueFlow::PathGraph

View File

@@ -3,7 +3,7 @@
*/
import rust
import utils.InlineFlowTest
import utils.test.InlineFlowTest
import codeql.rust.dataflow.DataFlow
import codeql.rust.dataflow.FlowSummary
import codeql.rust.dataflow.TaintTracking

View File

@@ -1,7 +1,7 @@
import rust
import codeql.rust.dataflow.DataFlow
import codeql.rust.Concepts
import utils.InlineFlowTest
import utils.test.InlineFlowTest
/**
* Configuration for flow from any threat model source to an argument of the function `sink`.

View File

@@ -1,2 +1,2 @@
query: queries/summary/TaintSources.ql
postprocess: utils/InlineExpectationsTestQuery.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

View File

@@ -3,7 +3,7 @@
*/
import rust
import utils.InlineFlowTest
import utils.test.InlineFlowTest
import DefaultFlowTest
import TaintFlow::PathGraph

View File

@@ -1,5 +1,5 @@
import rust
import utils.InlineExpectationsTest
import utils.test.InlineExpectationsTest
query predicate variable(Variable v) { any() }

View File

@@ -1,4 +1,4 @@
query: queries/security/CWE-089/SqlInjection.ql
postprocess:
- utils/PrettyPrintModels.ql
- utils/InlineExpectationsTestQuery.ql
- utils/test/PrettyPrintModels.ql
- utils/test/InlineExpectationsTestQuery.ql

View File

@@ -1,6 +1,6 @@
import rust
import codeql.rust.security.SqlInjectionExtensions
import utils.InlineExpectationsTest
import utils.test.InlineExpectationsTest
module SqlSinksTest implements TestSig {
string getARelevantTag() { result = "sql-sink" }

View File

@@ -1,2 +1,2 @@
query: queries/security/CWE-327/BrokenCryptoAlgorithm.ql
postprocess: utils/InlineExpectationsTestQuery.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

View File

@@ -1,2 +1,2 @@
query: queries/security/CWE-696/BadCtorInitialization.ql
postprocess: utils/InlineExpectationsTestQuery.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

View File

@@ -1,2 +1,2 @@
query: queries/unusedentities/UnreachableCode.ql
postprocess: utils/InlineExpectationsTestQuery.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

View File

@@ -1,2 +1,2 @@
query: queries/unusedentities/UnusedValue.ql
postprocess: utils/InlineExpectationsTestQuery.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

View File

@@ -1,2 +1,2 @@
query: queries/unusedentities/UnusedVariable.ql
postprocess: utils/InlineExpectationsTestQuery.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

View File

@@ -1,8 +0,0 @@
/**
* Inline expectation tests for Rust.
* See `shared/util/codeql/util/test/InlineExpectationsTest.qll`
*/
private import codeql.util.test.InlineExpectationsTest
private import internal.InlineExpectationsTestImpl
import Make<Impl>

View File

@@ -1,21 +0,0 @@
/**
* @kind test-postprocess
*/
private import rust
private import codeql.util.test.InlineExpectationsTest as T
private import internal.InlineExpectationsTestImpl
import T::TestPostProcessing
import T::TestPostProcessing::Make<Impl, Input>
private module Input implements T::TestPostProcessing::InputSig<Impl> {
string getRelativeUrl(Location location) {
exists(File f, int startline, int startcolumn, int endline, int endcolumn |
location.hasLocationInfo(_, startline, startcolumn, endline, endcolumn) and
f = location.getFile()
|
result =
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
)
}
}

View File

@@ -1,49 +0,0 @@
/**
* Inline flow tests for Rust.
* See `shared/util/codeql/dataflow/test/InlineFlowTest.qll`
*/
import rust
private import codeql.dataflow.test.InlineFlowTest
private import codeql.rust.controlflow.CfgNodes
private import codeql.rust.dataflow.DataFlow
private import codeql.rust.dataflow.internal.DataFlowImpl
private import codeql.rust.dataflow.internal.TaintTrackingImpl
private import codeql.rust.dataflow.internal.ModelsAsData as MaD
private import internal.InlineExpectationsTestImpl as InlineExpectationsTestImpl
/**
* Holds if the target expression of `call` is a path and the string
* representation of the path has `name` as a prefix.
*/
bindingset[name]
private predicate callTargetName(CallExprCfgNode call, string name) {
call.getFunction().(PathExprCfgNode).toString().matches(name + "%")
}
private module FlowTestImpl implements InputSig<Location, RustDataFlow> {
predicate defaultSource(DataFlow::Node source) { callTargetName(source.asExpr(), "source") }
predicate defaultSink(DataFlow::Node sink) {
any(CallExprCfgNode call | callTargetName(call, "sink")).getArgument(_) = sink.asExpr()
}
private string getSourceArgString(DataFlow::Node src) {
defaultSource(src) and
result = src.asExpr().(CallExprCfgNode).getArgument(0).toString()
}
bindingset[src, sink]
string getArgString(DataFlow::Node src, DataFlow::Node sink) {
(
result = getSourceArgString(src)
or
not exists(getSourceArgString(src)) and result = ""
) and
exists(sink)
}
predicate interpretModelForTest = MaD::interpretModelForTest/2;
}
import InlineFlowTestMake<Location, RustDataFlow, RustTaintTracking, InlineExpectationsTestImpl::Impl, FlowTestImpl>

View File

@@ -1,7 +0,0 @@
/**
* @kind test-postprocess
*/
import codeql.rust.dataflow.internal.ModelsAsData
import codeql.dataflow.test.ProvenancePathGraph
import codeql.dataflow.test.ProvenancePathGraph::TestPostProcessing::TranslateProvenanceResults<interpretModelForTest/2>

View File

@@ -1,8 +0,0 @@
private import codeql.dataflow.DataFlow as DF
private import codeql.dataflow.test.ProvenancePathGraph as Graph
private import codeql.rust.dataflow.internal.ModelsAsData
/** Transforms a `PathGraph` by printing the provenance information. */
module ShowProvenance<Graph::PathNodeSig PathNode, DF::PathGraphSig<PathNode> PathGraph> {
import Graph::ShowProvenance<interpretModelForTest/2, PathNode, PathGraph>
}

View File

@@ -1,12 +0,0 @@
private import rust as R
private import R
private import codeql.util.test.InlineExpectationsTest
module Impl implements InlineExpectationsTestSig {
class ExpectationComment extends R::Comment {
/** Gets the contents of the given comment, _without_ the preceding comment marker (`//`). */
string getContents() { result = this.getCommentText() }
}
class Location = R::Location;
}