Skip to content

Commit 01f9b42

Browse files
authored
Merge branch 'main' into varfps
2 parents ee13a49 + 949cfc3 commit 01f9b42

File tree

89 files changed

+3251
-1229
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+3251
-1229
lines changed

config/identical-files.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@
282282
"java/ql/lib/semmle/code/java/internal/OverlayXml.qll",
283283
"go/ql/lib/semmle/go/internal/OverlayXml.qll",
284284
"python/ql/lib/semmle/python/internal/OverlayXml.qll",
285-
"csharp/ql/lib/semmle/code/csharp/internal/OverlayXml.qll"
285+
"csharp/ql/lib/semmle/code/csharp/internal/OverlayXml.qll",
286+
"cpp/ql/lib/semmle/code/cpp/internal/OverlayXml.qll"
286287
]
287288
}

cpp/ql/lib/semmle/code/cpp/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,19 @@ module SourceSinkInterpretationInput implements
148148
)
149149
}
150150

151+
predicate barrierElement(
152+
Element n, string output, string kind, Public::Provenance provenance, string model
153+
) {
154+
none()
155+
}
156+
157+
predicate barrierGuardElement(
158+
Element n, string input, Public::AcceptingValue acceptingvalue, string kind,
159+
Public::Provenance provenance, string model
160+
) {
161+
none()
162+
}
163+
151164
private newtype TInterpretNode =
152165
TElement_(Element n) or
153166
TNode_(Node n)

cpp/ql/lib/semmle/code/cpp/internal/Overlay.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
* Defines entity discard predicates for C++ overlay analysis.
33
*/
44

5+
private import OverlayXml
6+
57
/**
68
* Holds always for the overlay variant and never for the base variant.
79
* This local predicate is used to define local predicates that behave
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
overlay[local]
2+
module;
3+
4+
/**
5+
* A local predicate that always holds for the overlay variant and never holds for the base variant.
6+
* This is used to define local predicates that behave differently for the base and overlay variant.
7+
*/
8+
private predicate isOverlay() { databaseMetadata("isOverlay", "true") }
9+
10+
private string getXmlFile(@xmllocatable locatable) {
11+
exists(@location_default location, @file file | xmllocations(locatable, location) |
12+
locations_default(location, file, _, _, _, _) and
13+
files(file, result)
14+
)
15+
}
16+
17+
private string getXmlFileInBase(@xmllocatable locatable) {
18+
not isOverlay() and
19+
result = getXmlFile(locatable)
20+
}
21+
22+
/**
23+
* Holds if the given `file` was extracted as part of the overlay and was extracted by the HTML/XML
24+
* extractor.
25+
*/
26+
private predicate overlayXmlExtracted(string file) {
27+
isOverlay() and
28+
exists(@xmllocatable locatable |
29+
not files(locatable, _) and not xmlNs(locatable, _, _, _) and file = getXmlFile(locatable)
30+
)
31+
}
32+
33+
/**
34+
* Holds if the given XML `locatable` should be discarded, because it is part of the overlay base
35+
* and is in a file that was also extracted as part of the overlay database.
36+
*/
37+
overlay[discard_entity]
38+
private predicate discardXmlLocatable(@xmllocatable locatable) {
39+
exists(string file | file = getXmlFileInBase(locatable) |
40+
overlayChangedFiles(file)
41+
or
42+
// The HTML/XML extractor is currently not incremental and may extract more files than those
43+
// included in overlayChangedFiles.
44+
overlayXmlExtracted(file)
45+
)
46+
}

csharp/documentation/library-coverage/coverage.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Microsoft.VisualBasic,,,6,,,,,,,,,,,,,,,,,,,1,5
4040
Microsoft.Win32,,4,2,,,,,,,,,,,,,,,,,,4,,2
4141
Mono.Linker,,,278,,,,,,,,,,,,,,,,,,,127,151
4242
MySql.Data.MySqlClient,48,,,,,,,,,,,,48,,,,,,,,,,
43+
NHibernate,3,,,,,,,,,,,,3,,,,,,,,,,
4344
Newtonsoft.Json,,,91,,,,,,,,,,,,,,,,,,,73,18
4445
ServiceStack,194,,7,27,,,,,75,,,,92,,,,,,,,,7,
4546
SourceGenerators,,,5,,,,,,,,,,,,,,,,,,,,5

csharp/documentation/library-coverage/coverage.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ C# framework & library support
99
Framework / library,Package,Flow sources,Taint & value steps,Sinks (total),`CWE-079` :sub:`Cross-site scripting`
1010
`ServiceStack <https://servicestack.net/>`_,"``ServiceStack.*``, ``ServiceStack``",,7,194,
1111
System,"``System.*``, ``System``",47,12241,54,5
12-
Others,"``Amazon.Lambda.APIGatewayEvents``, ``Amazon.Lambda.Core``, ``Dapper``, ``ILCompiler``, ``ILLink.RoslynAnalyzer``, ``ILLink.Shared``, ``ILLink.Tasks``, ``Internal.IL``, ``Internal.Pgo``, ``Internal.TypeSystem``, ``Microsoft.ApplicationBlocks.Data``, ``Microsoft.AspNetCore.Components``, ``Microsoft.AspNetCore.Http``, ``Microsoft.AspNetCore.Mvc``, ``Microsoft.AspNetCore.WebUtilities``, ``Microsoft.CSharp``, ``Microsoft.Data.SqlClient``, ``Microsoft.Diagnostics.Tools.Pgo``, ``Microsoft.DotNet.Build.Tasks``, ``Microsoft.DotNet.PlatformAbstractions``, ``Microsoft.EntityFrameworkCore``, ``Microsoft.Extensions.Caching.Distributed``, ``Microsoft.Extensions.Caching.Memory``, ``Microsoft.Extensions.Configuration``, ``Microsoft.Extensions.DependencyInjection``, ``Microsoft.Extensions.DependencyModel``, ``Microsoft.Extensions.Diagnostics.Metrics``, ``Microsoft.Extensions.FileProviders``, ``Microsoft.Extensions.FileSystemGlobbing``, ``Microsoft.Extensions.Hosting``, ``Microsoft.Extensions.Http``, ``Microsoft.Extensions.Logging``, ``Microsoft.Extensions.Options``, ``Microsoft.Extensions.Primitives``, ``Microsoft.Interop``, ``Microsoft.JSInterop``, ``Microsoft.NET.Build.Tasks``, ``Microsoft.VisualBasic``, ``Microsoft.Win32``, ``Mono.Linker``, ``MySql.Data.MySqlClient``, ``Newtonsoft.Json``, ``SourceGenerators``, ``Windows.Security.Cryptography.Core``",60,2257,159,4
13-
Totals,,107,14505,407,9
12+
Others,"``Amazon.Lambda.APIGatewayEvents``, ``Amazon.Lambda.Core``, ``Dapper``, ``ILCompiler``, ``ILLink.RoslynAnalyzer``, ``ILLink.Shared``, ``ILLink.Tasks``, ``Internal.IL``, ``Internal.Pgo``, ``Internal.TypeSystem``, ``Microsoft.ApplicationBlocks.Data``, ``Microsoft.AspNetCore.Components``, ``Microsoft.AspNetCore.Http``, ``Microsoft.AspNetCore.Mvc``, ``Microsoft.AspNetCore.WebUtilities``, ``Microsoft.CSharp``, ``Microsoft.Data.SqlClient``, ``Microsoft.Diagnostics.Tools.Pgo``, ``Microsoft.DotNet.Build.Tasks``, ``Microsoft.DotNet.PlatformAbstractions``, ``Microsoft.EntityFrameworkCore``, ``Microsoft.Extensions.Caching.Distributed``, ``Microsoft.Extensions.Caching.Memory``, ``Microsoft.Extensions.Configuration``, ``Microsoft.Extensions.DependencyInjection``, ``Microsoft.Extensions.DependencyModel``, ``Microsoft.Extensions.Diagnostics.Metrics``, ``Microsoft.Extensions.FileProviders``, ``Microsoft.Extensions.FileSystemGlobbing``, ``Microsoft.Extensions.Hosting``, ``Microsoft.Extensions.Http``, ``Microsoft.Extensions.Logging``, ``Microsoft.Extensions.Options``, ``Microsoft.Extensions.Primitives``, ``Microsoft.Interop``, ``Microsoft.JSInterop``, ``Microsoft.NET.Build.Tasks``, ``Microsoft.VisualBasic``, ``Microsoft.Win32``, ``Mono.Linker``, ``MySql.Data.MySqlClient``, ``NHibernate``, ``Newtonsoft.Json``, ``SourceGenerators``, ``Windows.Security.Cryptography.Core``",60,2257,162,4
13+
Totals,,107,14505,410,9
1414

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Added implicit reads of `System.Collections.Generic.KeyValuePair.Value` at taint-tracking sinks and at inputs to additional taint steps. As a result, taint-tracking queries will now produce more results when a container is tainted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
extensions:
2+
- addsTo:
3+
pack: codeql/csharp-all
4+
extensible: sinkModel
5+
data:
6+
- ["NHibernate", "ISession", True, "CreateSQLQuery", "(System.String)", "", "Argument[0]", "sql-injection", "manual"]
7+
- ["NHibernate", "IStatelessSession", True, "CreateSQLQuery", "(System.String)", "", "Argument[0]", "sql-injection", "manual"]
8+
- ["NHibernate.Impl", "AbstractSessionImpl", True, "CreateSQLQuery", "(System.String)", "", "Argument[0]", "sql-injection", "manual"]

csharp/ql/lib/semmle/code/csharp/controlflow/Guards.qll

Lines changed: 47 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,40 @@ module Internal {
842842
e3 = any(NullCoalescingExpr nce | e1 = nce.getLeftOperand() and e2 = nce.getRightOperand())
843843
}
844844

845+
predicate nullValueImplied(Expr e) {
846+
nullValue(e)
847+
or
848+
exists(Expr e1 | nullValueImplied(e1) and nullValueImpliedUnary(e1, e))
849+
or
850+
exists(Expr e1, Expr e2 |
851+
nullValueImplied(e1) and nullValueImplied(e2) and nullValueImpliedBinary(e1, e2, e)
852+
)
853+
or
854+
e =
855+
any(Ssa::Definition def |
856+
forex(Ssa::Definition u | u = def.getAnUltimateDefinition() | nullDef(u))
857+
).getARead()
858+
}
859+
860+
private predicate nullDef(Ssa::ExplicitDefinition def) {
861+
nullValueImplied(def.getADefinition().getSource())
862+
}
863+
864+
predicate nonNullValueImplied(Expr e) {
865+
nonNullValue(e)
866+
or
867+
exists(Expr e1 | nonNullValueImplied(e1) and nonNullValueImpliedUnary(e1, e))
868+
or
869+
e =
870+
any(Ssa::Definition def |
871+
forex(Ssa::Definition u | u = def.getAnUltimateDefinition() | nonNullDef(u))
872+
).getARead()
873+
}
874+
875+
private predicate nonNullDef(Ssa::ExplicitDefinition def) {
876+
nonNullValueImplied(def.getADefinition().getSource())
877+
}
878+
845879
/** A callable that always returns a non-`null` value. */
846880
private class NonNullCallable extends Callable {
847881
NonNullCallable() { this = any(SystemObjectClass c).getGetTypeMethod() }
@@ -936,154 +970,21 @@ module Internal {
936970
e = any(BinaryArithmeticOperation bao | result = bao.getAnOperand())
937971
}
938972

939-
// The predicates in this module should be evaluated in the same stage as the CFG
940-
// construction stage. This is to avoid recomputation of pre-basic-blocks and
941-
// pre-SSA predicates
942-
private module PreCfg {
943-
private import semmle.code.csharp.controlflow.internal.PreBasicBlocks as PreBasicBlocks
944-
private import semmle.code.csharp.controlflow.internal.PreSsa
945-
946-
private predicate nullDef(PreSsa::Definition def) {
947-
nullValueImplied(def.getDefinition().getSource())
948-
}
949-
950-
private predicate nonNullDef(PreSsa::Definition def) {
951-
nonNullValueImplied(def.getDefinition().getSource())
952-
}
953-
954-
private predicate emptyDef(PreSsa::Definition def) {
955-
emptyValue(def.getDefinition().getSource())
956-
}
957-
958-
private predicate nonEmptyDef(PreSsa::Definition def) {
959-
nonEmptyValue(def.getDefinition().getSource())
960-
}
961-
962-
deprecated predicate isGuard(Expr e, GuardValue val) {
963-
(
964-
e.getType() instanceof BoolType and
965-
not e instanceof BoolLiteral and
966-
not e instanceof SwitchCaseExpr and
967-
not e instanceof PatternExpr and
968-
exists(val.asBooleanValue())
969-
or
970-
e instanceof DereferenceableExpr and
971-
val.isNullness(_)
972-
) and
973-
not e = any(ExprStmt es).getExpr() and
974-
not e = any(LocalVariableDeclStmt s).getAVariableDeclExpr()
975-
}
976-
977-
cached
978-
private module CachedWithCfg {
979-
private import semmle.code.csharp.Caching
980-
981-
private predicate firstReadSameVarUniquePredecessor(
982-
PreSsa::Definition def, AssignableRead read
983-
) {
984-
read = def.getAFirstRead() and
985-
(
986-
not PreSsa::adjacentReadPairSameVar(_, read)
987-
or
988-
read = unique(AssignableRead read0 | PreSsa::adjacentReadPairSameVar(read0, read))
989-
)
990-
}
991-
992-
cached
993-
predicate nullValueImplied(Expr e) {
994-
nullValue(e)
995-
or
996-
exists(Expr e1 | nullValueImplied(e1) and nullValueImpliedUnary(e1, e))
997-
or
998-
exists(Expr e1, Expr e2 |
999-
nullValueImplied(e1) and nullValueImplied(e2) and nullValueImpliedBinary(e1, e2, e)
1000-
)
1001-
or
1002-
e =
1003-
any(PreSsa::Definition def |
1004-
forex(PreSsa::Definition u | u = def.getAnUltimateDefinition() | nullDef(u))
1005-
).getARead()
1006-
}
1007-
1008-
cached
1009-
predicate nonNullValueImplied(Expr e) {
1010-
nonNullValue(e)
1011-
or
1012-
exists(Expr e1 | nonNullValueImplied(e1) and nonNullValueImpliedUnary(e1, e))
1013-
or
1014-
e =
1015-
any(PreSsa::Definition def |
1016-
forex(PreSsa::Definition u | u = def.getAnUltimateDefinition() | nonNullDef(u))
1017-
).getARead()
1018-
}
1019-
1020-
private predicate adjacentReadPairSameVarUniquePredecessor(
1021-
AssignableRead read1, AssignableRead read2
1022-
) {
1023-
PreSsa::adjacentReadPairSameVar(read1, read2) and
1024-
(
1025-
read1 = read2 and
1026-
read1 = unique(AssignableRead other | PreSsa::adjacentReadPairSameVar(other, read2))
1027-
or
1028-
read1 =
1029-
unique(AssignableRead other |
1030-
PreSsa::adjacentReadPairSameVar(other, read2) and other != read2
1031-
)
1032-
)
1033-
}
1034-
1035-
cached
1036-
predicate emptyValue(Expr e) {
1037-
e.(ArrayCreation).getALengthArgument().getValue().toInt() = 0
1038-
or
1039-
e.(ArrayInitializer).hasNoElements()
1040-
or
1041-
exists(Expr mid | emptyValue(mid) |
1042-
mid = e.(AssignExpr).getRValue()
1043-
or
1044-
mid = e.(Cast).getExpr()
1045-
)
1046-
or
1047-
exists(PreSsa::Definition def | emptyDef(def) | firstReadSameVarUniquePredecessor(def, e))
1048-
or
1049-
exists(MethodCall mc |
1050-
mc.getTarget().getAnUltimateImplementee().getUnboundDeclaration() =
1051-
any(SystemCollectionsGenericICollectionInterface c).getClearMethod() and
1052-
adjacentReadPairSameVarUniquePredecessor(mc.getQualifier(), e)
1053-
)
1054-
}
1055-
1056-
cached
1057-
predicate nonEmptyValue(Expr e) {
1058-
forex(Expr length | length = e.(ArrayCreation).getALengthArgument() |
1059-
length.getValue().toInt() != 0
1060-
)
1061-
or
1062-
e.(ArrayInitializer).getNumberOfElements() > 0
1063-
or
1064-
exists(Expr mid | nonEmptyValue(mid) |
1065-
mid = e.(AssignExpr).getRValue()
1066-
or
1067-
mid = e.(Cast).getExpr()
1068-
)
1069-
or
1070-
exists(PreSsa::Definition def | nonEmptyDef(def) |
1071-
firstReadSameVarUniquePredecessor(def, e)
1072-
)
1073-
or
1074-
exists(MethodCall mc |
1075-
mc.getTarget().getAnUltimateImplementee().getUnboundDeclaration() =
1076-
any(SystemCollectionsGenericICollectionInterface c).getAddMethod() and
1077-
adjacentReadPairSameVarUniquePredecessor(mc.getQualifier(), e)
1078-
)
1079-
}
1080-
}
1081-
1082-
import CachedWithCfg
973+
deprecated predicate isGuard(Expr e, GuardValue val) {
974+
(
975+
e.getType() instanceof BoolType and
976+
not e instanceof BoolLiteral and
977+
not e instanceof SwitchCaseExpr and
978+
not e instanceof PatternExpr and
979+
exists(val.asBooleanValue())
980+
or
981+
e instanceof DereferenceableExpr and
982+
val.isNullness(_)
983+
) and
984+
not e = any(ExprStmt es).getExpr() and
985+
not e = any(LocalVariableDeclStmt s).getAVariableDeclExpr()
1083986
}
1084987

1085-
import PreCfg
1086-
1087988
private predicate interestingDescendantCandidate(Expr e) {
1088989
guardControls(e, _, _)
1089990
or

0 commit comments

Comments
 (0)