Skip to content

Commit 11165d5

Browse files
committed
C++: Fix queries I forgot after merging github/codeql#20485.
1 parent 68be4b0 commit 11165d5

File tree

6 files changed

+18
-14
lines changed

6 files changed

+18
-14
lines changed

c/cert/src/rules/EXP16-C/DoNotCompareFunctionPointersToConstantValues.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ class ExplicitComparison extends EffectivelyComparison, FinalComparisonOperation
5353

5454
class ImplicitComparison extends EffectivelyComparison, GuardCondition instanceof Expr {
5555
ImplicitComparison() {
56+
this.valueControlsEdge(_, _, _) and
5657
this instanceof FunctionExpr and
57-
not getParent() instanceof ComparisonOperation
58+
not super.getParent() instanceof ComparisonOperation
5859
}
5960

6061
override string getExplanation() { result = "$@ undergoes implicit constant comparison." }

cpp/autosar/src/rules/A4-7-1/IntegerExpressionLeadToDataLoss.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ from InterestingOverflowingOperation e
2323
where
2424
not isExcluded(e, IntegerConversionPackage::integerExpressionLeadToDataLossQuery()) and
2525
// Not within a guard condition
26-
not exists(GuardCondition gc | gc.getAChild*() = e) and
26+
not e.getParent*().(GuardCondition).valueControlsEdge(_, _, _) and
2727
// Not guarded by a check, where the check is not an invalid overflow check
2828
not e.hasValidPreCheck() and
2929
// Covered by `IntMultToLong.ql` instead

cpp/cert/src/rules/MEM52-CPP/DetectAndHandleMemoryAllocationErrors.ql

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ class NoThrowAllocExprWrapperFunction extends Function {
6363
n.getEnclosingFunction() = this and
6464
DataFlow::localExprFlow(n, any(ReturnStmt rs).getExpr()) and
6565
// Not checked in this wrapper function
66-
not exists(GuardCondition gc | DataFlow::localExprFlow(n, gc.(Expr).getAChild*()))
66+
not exists(BasicBlock bb |
67+
pragma[only_bind_out](bb.getEnclosingFunction()) =
68+
pragma[only_bind_out](n.getEnclosingFunction()) and
69+
n.(GuardCondition).valueControlsEdge(bb, _, _)
70+
)
6771
}
6872

6973
/** Gets the underlying nothrow allocation ultimately being wrapped. */
@@ -84,7 +88,9 @@ module NoThrowNewErrorCheckConfig implements DataFlow::ConfigSig {
8488
source.asExpr() instanceof NotWrappedNoThrowAllocExpr
8589
}
8690

87-
predicate isSink(DataFlow::Node sink) { sink.asExpr() = any(GuardCondition gc).getAChild*() }
91+
predicate isSink(DataFlow::Node sink) {
92+
sink.asExpr().(GuardCondition).valueControlsEdge(_, _, _)
93+
}
8894
}
8995

9096
module NoThrowNewErrorCheckFlow = DataFlow::Global<NoThrowNewErrorCheckConfig>;
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
WARNING: module 'DataFlow' has been deprecated and may be removed in future (DetectAndHandleMemoryAllocationErrors.ql:64,5-13)
2-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (DetectAndHandleMemoryAllocationErrors.ql:66,36-44)
3-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (DetectAndHandleMemoryAllocationErrors.ql:82,46-54)
4-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (DetectAndHandleMemoryAllocationErrors.ql:83,22-30)
5-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (DetectAndHandleMemoryAllocationErrors.ql:87,20-28)
6-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (DetectAndHandleMemoryAllocationErrors.ql:90,35-43)
7-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (DetectAndHandleMemoryAllocationErrors.ql:95,38-46)
2+
WARNING: module 'DataFlow' has been deprecated and may be removed in future (DetectAndHandleMemoryAllocationErrors.ql:86,46-54)
3+
WARNING: module 'DataFlow' has been deprecated and may be removed in future (DetectAndHandleMemoryAllocationErrors.ql:87,22-30)
4+
WARNING: module 'DataFlow' has been deprecated and may be removed in future (DetectAndHandleMemoryAllocationErrors.ql:91,20-28)
5+
WARNING: module 'DataFlow' has been deprecated and may be removed in future (DetectAndHandleMemoryAllocationErrors.ql:96,35-43)
6+
WARNING: module 'DataFlow' has been deprecated and may be removed in future (DetectAndHandleMemoryAllocationErrors.ql:101,38-46)
87
| test.cpp:24:7:24:34 | new | nothrow new allocation of $@ returns here without a subsequent check to see whether the pointer is valid. | test.cpp:24:7:24:34 | new | StructA * |
98
| test.cpp:40:17:40:38 | call to allocate_without_check | nothrow new allocation of $@ returns here without a subsequent check to see whether the pointer is valid. | test.cpp:35:17:35:44 | new | StructA * |

cpp/common/src/codingstandards/cpp/rules/functionerroneousreturnvaluenottested/FunctionErroneousReturnValueNotTested.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ query predicate problems(FunctionCall fc, string message) {
5555
"vwprintf", "vfwprintf", "vswprintf", "vwprintf_s", "vfwprintf_s", "vswprintf_s",
5656
"vsnwprintf_s"
5757
]) and
58-
not exists(GuardCondition gc |
59-
DataFlow::localFlow(DataFlow::exprNode(fc), DataFlow::exprNode(gc.(Expr).getAChild*()))
60-
) and
58+
not fc.(GuardCondition).valueControlsEdge(_, _, _) and
6159
message = "Return value from " + fc.getTarget().getName() + " is not tested for errors."
6260
}

cpp/common/src/codingstandards/cpp/rules/unsignedoperationwithconstantoperandswraps/UnsignedOperationWithConstantOperandsWraps.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ query predicate problems(InterestingOverflowingOperation op, string message) {
1818
not isExcluded(op, getQuery()) and
1919
op.getType().getUnderlyingType().(IntegralType).isUnsigned() and
2020
// Not within a guard condition
21-
not exists(GuardCondition gc | gc.getAChild*() = op) and
21+
not op.getParent*().(GuardCondition).valueControlsEdge(_, _, _) and
2222
// Not guarded by a check, where the check is not an invalid overflow check
2323
not op.hasValidPreCheck() and
2424
// Is not checked after the operation

0 commit comments

Comments
 (0)