Skip to content

Commit 96ed659

Browse files
authored
Merge branch 'main' into github-only
2 parents 6779c66 + bafea91 commit 96ed659

File tree

186 files changed

+23916
-21073
lines changed

Some content is hidden

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

186 files changed

+23916
-21073
lines changed

.github/workflows/qhelp-pr-preview.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ jobs:
7777
done < "${RUNNER_TEMP}/paths.txt" >> comment_body.txt
7878
exit "${EXIT_CODE}"
7979
80-
- if: always()
80+
- if: ${{ !cancelled() }}
8181
uses: actions/upload-artifact@v3
8282
with:
8383
name: comment

cpp/ql/lib/change-notes/2024-02-06-flow-out-barrier-function.md

Lines changed: 0 additions & 4 deletions
This file was deleted.

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/SsaInternals.qll

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@ private import codeql.ssa.Ssa as SsaImplCommon
22
private import semmle.code.cpp.ir.IR
33
private import DataFlowUtil
44
private import DataFlowImplCommon as DataFlowImplCommon
5-
private import semmle.code.cpp.ir.dataflow.internal.ModelUtil
65
private import semmle.code.cpp.models.interfaces.Allocation as Alloc
76
private import semmle.code.cpp.models.interfaces.DataFlow as DataFlow
8-
private import semmle.code.cpp.models.interfaces.FlowOutBarrier as FOB
9-
private import semmle.code.cpp.models.interfaces.FunctionInputsAndOutputs as FIO
107
private import semmle.code.cpp.ir.internal.IRCppLanguage
118
private import DataFlowPrivate
129
private import ssa0.SsaInternals as SsaInternals0
@@ -797,30 +794,10 @@ private Node getAPriorDefinition(SsaDefOrUse defOrUse) {
797794
)
798795
}
799796

800-
/**
801-
* Holds if there should not be use-use flow out of `n` (or a conversion that
802-
* flows to `n`).
803-
*/
804-
private predicate modeledFlowBarrier(Node n) {
805-
exists(FIO::FunctionInput input, CallInstruction call |
806-
call.getStaticCallTarget().(FOB::FlowOutBarrierFunction).isFlowOutBarrier(input) and
807-
n = callInput(call, input)
808-
)
809-
or
810-
exists(Operand operand, Instruction instr, Node n0, int indirectionIndex |
811-
modeledFlowBarrier(n0) and
812-
nodeHasInstruction(n0, instr, indirectionIndex) and
813-
conversionFlow(operand, instr, false, _) and
814-
nodeHasOperand(n, operand, indirectionIndex)
815-
)
816-
}
817-
818797
/** Holds if there is def-use or use-use flow from `nodeFrom` to `nodeTo`. */
819798
predicate ssaFlow(Node nodeFrom, Node nodeTo) {
820799
exists(Node nFrom, boolean uncertain, SsaDefOrUse defOrUse |
821-
ssaFlowImpl(defOrUse, nFrom, nodeTo, uncertain) and
822-
not modeledFlowBarrier(nFrom) and
823-
nodeFrom != nodeTo
800+
ssaFlowImpl(defOrUse, nFrom, nodeTo, uncertain) and nodeFrom != nodeTo
824801
|
825802
if uncertain = true then nodeFrom = [nFrom, getAPriorDefinition(defOrUse)] else nodeFrom = nFrom
826803
)

cpp/ql/lib/semmle/code/cpp/models/implementations/Memset.qll

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,28 @@ private class MemsetFunctionModel extends ArrayFunction, DataFlowFunction, Alias
2222
])
2323
}
2424

25+
/**
26+
* Gets the index of the parameter that specifies the fill character to insert, if any.
27+
*/
28+
private int getFillCharParameterIndex() {
29+
(
30+
this.hasGlobalOrStdOrBslName("memset")
31+
or
32+
this.hasGlobalOrStdName("wmemset")
33+
or
34+
this.hasGlobalName(["__builtin_memset", "__builtin_memset_chk"])
35+
) and
36+
result = 1
37+
}
38+
2539
override predicate hasArrayOutput(int bufParam) { bufParam = 0 }
2640

2741
override predicate hasDataFlow(FunctionInput input, FunctionOutput output) {
2842
input.isParameter(0) and
2943
output.isReturnValue()
44+
or
45+
input.isParameter(this.getFillCharParameterIndex()) and
46+
(output.isParameterDeref(0) or output.isReturnValueDeref())
3047
}
3148

3249
override predicate hasArrayWithVariableSize(int bufParam, int countParam) {

cpp/ql/lib/semmle/code/cpp/models/implementations/Swap.qll

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import semmle.code.cpp.models.interfaces.DataFlow
22
import semmle.code.cpp.models.interfaces.Taint
33
import semmle.code.cpp.models.interfaces.Alias
4-
import semmle.code.cpp.models.interfaces.FlowOutBarrier
54

65
/**
76
* The standard function `swap`. A use of `swap` looks like this:
87
* ```
98
* std::swap(obj1, obj2)
109
* ```
1110
*/
12-
private class Swap extends DataFlowFunction, FlowOutBarrierFunction {
11+
private class Swap extends DataFlowFunction {
1312
Swap() { this.hasQualifiedName(["std", "bsl"], "swap") }
1413

1514
override predicate hasDataFlow(FunctionInput input, FunctionOutput output) {
@@ -19,8 +18,6 @@ private class Swap extends DataFlowFunction, FlowOutBarrierFunction {
1918
input.isParameterDeref(1) and
2019
output.isParameterDeref(0)
2120
}
22-
23-
override predicate isFlowOutBarrier(FunctionInput input) { input.isParameterDeref([0, 1]) }
2421
}
2522

2623
/**
@@ -29,9 +26,7 @@ private class Swap extends DataFlowFunction, FlowOutBarrierFunction {
2926
* obj1.swap(obj2)
3027
* ```
3128
*/
32-
private class MemberSwap extends TaintFunction, MemberFunction, AliasFunction,
33-
FlowOutBarrierFunction
34-
{
29+
private class MemberSwap extends TaintFunction, MemberFunction, AliasFunction {
3530
MemberSwap() {
3631
this.hasName("swap") and
3732
this.getNumberOfParameters() = 1 and
@@ -52,8 +47,4 @@ private class MemberSwap extends TaintFunction, MemberFunction, AliasFunction,
5247
override predicate parameterEscapesOnlyViaReturn(int index) { index = 0 }
5348

5449
override predicate parameterIsAlwaysReturned(int index) { index = 0 }
55-
56-
override predicate isFlowOutBarrier(FunctionInput input) {
57-
input.isQualifierObject() or input.isParameterDeref(0)
58-
}
5950
}

cpp/ql/lib/semmle/code/cpp/models/interfaces/FlowOutBarrier.qll

Lines changed: 0 additions & 26 deletions
This file was deleted.

cpp/ql/test/library-tests/dataflow/dataflow-tests/dataflow-consistency.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ postWithInFlow
165165
| test.cpp:931:5:931:18 | global_pointer [post update] | PostUpdateNode should not be the target of local flow. |
166166
| test.cpp:932:5:932:19 | * ... [post update] | PostUpdateNode should not be the target of local flow. |
167167
| test.cpp:932:6:932:19 | global_pointer [inner post update] | PostUpdateNode should not be the target of local flow. |
168+
| test.cpp:1045:9:1045:11 | ref arg buf | PostUpdateNode should not be the target of local flow. |
168169
viableImplInCallContextTooLarge
169170
uniqueParameterNodeAtPosition
170171
uniqueParameterNodePosition

cpp/ql/test/library-tests/dataflow/dataflow-tests/dataflow-ir-consistency.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ postWithInFlow
2525
| test.cpp:391:10:391:13 | memcpy output argument | PostUpdateNode should not be the target of local flow. |
2626
| test.cpp:400:10:400:13 | memcpy output argument | PostUpdateNode should not be the target of local flow. |
2727
| test.cpp:407:10:407:13 | memcpy output argument | PostUpdateNode should not be the target of local flow. |
28+
| test.cpp:1045:9:1045:11 | memset output argument | PostUpdateNode should not be the target of local flow. |
2829
viableImplInCallContextTooLarge
2930
uniqueParameterNodeAtPosition
3031
uniqueParameterNodePosition

cpp/ql/test/library-tests/dataflow/dataflow-tests/test-source-sink.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ irFlow
309309
| test.cpp:994:18:994:32 | *call to indirect_source | test.cpp:1003:19:1003:28 | *translated |
310310
| test.cpp:1021:18:1021:32 | *call to indirect_source | test.cpp:1027:19:1027:28 | *translated |
311311
| test.cpp:1021:18:1021:32 | *call to indirect_source | test.cpp:1031:19:1031:28 | *translated |
312+
| test.cpp:1045:14:1045:19 | call to source | test.cpp:1046:7:1046:10 | * ... |
312313
| true_upon_entry.cpp:9:11:9:16 | call to source | true_upon_entry.cpp:13:8:13:8 | x |
313314
| true_upon_entry.cpp:17:11:17:16 | call to source | true_upon_entry.cpp:21:8:21:8 | x |
314315
| true_upon_entry.cpp:27:9:27:14 | call to source | true_upon_entry.cpp:29:8:29:8 | x |

cpp/ql/test/library-tests/dataflow/dataflow-tests/test.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,4 +1037,11 @@ namespace test_gettext {
10371037
sink(translated); // clean
10381038
indirect_sink(translated); // clean
10391039
}
1040+
}
1041+
1042+
void* memset(void*, int, size_t);
1043+
1044+
void memset_test(char* buf) { // $ ast-def=buf
1045+
memset(buf, source(), 10);
1046+
sink(*buf); // $ ir MISSING: ast
10401047
}

0 commit comments

Comments
 (0)