Skip to content

Commit a9b659a

Browse files
authored
Merge pull request #1228 from MathiasVP/accept-test-changes-after-uninitialized-arrays
C++: Fix queries after github/codeql#23255
2 parents 3dc266e + ef11073 commit a9b659a

2 files changed

Lines changed: 15 additions & 15 deletions

File tree

‎c/cert/src/rules/MSC39-C/DoNotCallVaArgOnAVaListThatHasAnIndeterminateValue.ql‎

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,15 @@ class VaArgArg extends VaAccess {
4242
// rx_n = VariableAddress[p]
4343
// ...
4444
// ry_0 = Load[p] : &:rx_n
45-
// ry_1 = Load[?] : &:ry_n
45+
// ry_1 = Load[?] : &:ry_0
4646
// ry_2 = NextVarArg : ry_1
4747
//
48-
// The last occurrence of `va_list` that we have dataflow to is `ry_0` via an `OperandNode`,
49-
// and the simplest attachment between the AST and the IR is through `ry_2` and our parent AST
50-
// node, the `__builtin_vararg(...)` call.
51-
exists(IR::Operand ry0, IR::Instruction ry1, IR::NextVarArgInstruction ry2 |
52-
ry2.getAnOperand().getDef() = ry1 and
48+
// `ry_1` loads the `va_list` object that `p` refers to, and the simplest attachment between
49+
// the AST and the IR is through `ry_2` and our parent AST node, the `__builtin_vararg(...)`
50+
// call.
51+
exists(IR::NextVarArgInstruction ry2 |
5352
ry2.getAst() = this.getParent() and
54-
ry1.getAnOperand() = ry0 and
55-
result.(DataFlow::OperandNode).getOperand() = ry0
53+
result.asOperand() = ry2.getUnaryOperand()
5654
)
5755
}
5856
}
@@ -63,19 +61,20 @@ class VaArgArg extends VaAccess {
6361
class VaEndArg extends VaAccess {
6462
VaEndArg() { this = any(MacroInvocation m | m.getMacroName() = ["va_end"]).getExpr().getChild(0) }
6563

66-
override DataFlow::Node getDfn() { result.asExpr() = this }
64+
override DataFlow::Node getDfn() { result.asIndirectExpr() = this }
6765
}
6866

6967
/**
70-
* Dataflow configuration for flow from between `va_list` usages.
68+
* Dataflow configuration for flow from the initialization of a `va_list` object by `va_start` to
69+
* the uses of that object.
7170
*/
7271
module VaArgConfig implements DataFlow::ConfigSig {
73-
predicate isSource(DataFlow::Node src) {
74-
src.asUninitialized() =
75-
any(VariableDeclarationEntry m | m.getType().hasName("va_list")).getVariable()
76-
}
72+
predicate isSource(DataFlow::Node src) { src.asDefinition() instanceof BuiltInVarArgsStart }
7773

7874
predicate isSink(DataFlow::Node sink) { exists(VaAccess va_acc | sink = va_acc.getDfn()) }
75+
76+
// `va_copy` creates a new `va_list` object, so the copy is not the same object as the original.
77+
predicate isBarrier(DataFlow::Node node) { node.asDefinition() instanceof BuiltInVarArgCopy }
7978
}
8079

8180
module VaArgFlow = DataFlow::Global<VaArgConfig>;

‎cpp/misra/src/rules/RULE-8-7-1/PointerArithmeticFormsAnInvalidPointer.ql‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ class ArrayAllocation extends TArrayAllocation {
164164
result = this.asStackAllocation().getLength(inode.getIndirectionIndex())
165165
)
166166
or
167-
node.asUninitialized() = this.asStackAllocation().getVariable() and
167+
node.asInstruction().(UninitializedInstruction).getLocalVariable() =
168+
this.asStackAllocation().getVariable() and
168169
result = this.asStackAllocation().getLength(0)
169170
or
170171
node.asConvertedExpr() = this.asDynamicAllocation() and

0 commit comments

Comments
 (0)