Skip to content

Commit ff90ac7

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

File tree

6 files changed

+20
-15
lines changed

6 files changed

+20
-15
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: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,13 @@ class NoThrowAllocExprWrapperFunction extends Function {
6262
NoThrowAllocExprWrapperFunction() {
6363
n.getEnclosingFunction() = this and
6464
DataFlow::localExprFlow(n, any(ReturnStmt rs).getExpr()) and
65-
// Not checked in this wrapper function
66-
not exists(GuardCondition gc | DataFlow::localExprFlow(n, gc.(Expr).getAChild*()))
65+
// Not checked in this wrapper function. That is, the allocation is not a
66+
// guard condition which guards something inside the function.
67+
not exists(BasicBlock bb |
68+
pragma[only_bind_out](bb.getEnclosingFunction()) =
69+
pragma[only_bind_out](n.getEnclosingFunction()) and
70+
n.(GuardCondition).valueControlsEdge(bb, _, _)
71+
)
6772
}
6873

6974
/** Gets the underlying nothrow allocation ultimately being wrapped. */
@@ -84,7 +89,9 @@ module NoThrowNewErrorCheckConfig implements DataFlow::ConfigSig {
8489
source.asExpr() instanceof NotWrappedNoThrowAllocExpr
8590
}
8691

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

9097
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)