@@ -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 {
6361class 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 */
7271module 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
8180module VaArgFlow = DataFlow:: Global< VaArgConfig > ;
0 commit comments