Commit Graph

5109 Commits

Author SHA1 Message Date
Jonas Jensen
95f116eb48 Merge branch 'DefaultTaintTracking-argv' into dataflow-indirect-args 2020-03-26 20:47:50 +01:00
Jonas Jensen
2801941ca2 C++: Never track flow out of an argv argument
This change removes some duplicate results that will otherwise appear
due to https://github.com/Semmle/ql/pull/3123 and possibly
https://github.com/Semmle/ql/pull/2704.
2020-03-26 20:40:16 +01:00
Dave Bartolomeo
7879dde8b8 Merge pull request #3097 from jbj/detect-conflated-memory
C++: Implement Instruction.isResultConflated
2020-03-26 14:52:47 -04:00
Jonas Jensen
08c53d4a61 C++: Clean up the ParameterNode class tree
The new names are chosen to align with Java's `DataFlowUtil.qll`.
2020-03-26 11:57:53 +01:00
Mathias Vorreiter Pedersen
a43abaaed9 Merge branch 'master' into ir-flow-fields 2020-03-26 11:51:07 +01:00
Mathias Vorreiter Pedersen
c6c613840a C++: Removed toString from PostUpdateNodes. They were more confusing than helpful 2020-03-26 11:43:40 +01:00
Mathias Vorreiter Pedersen
fbef146a49 C++: Remove PositionalArgumentWithoutWriteSideEffectNode (since not all arguments need a PostUpdateNode). Also generalized the added flow rule in simpleLocalFlowStep since there isn't always a ChiInstruction - for instance of it's a write to a struct that only has a single field. 2020-03-26 11:39:20 +01:00
Robert Marsh
e6cdbb9bd2 Merge pull request #3121 from dbartol/dbartol/ir-generate-all-fixup
C++: Late fix for PR feedback
2020-03-25 17:58:01 -07:00
Jonas Jensen
b622d62d3c C++: Wire up param/arg indirections in data flow 2020-03-25 15:23:43 +01:00
Jonas Jensen
bc3bdbb11b C++: Improve QLDoc for Function.getParameter 2020-03-25 15:21:24 +01:00
Dave Bartolomeo
1edd492abf C++: Late fix for PR feedback
I missed this suggestion before I merged the original PR. Fixing it now before I forget.
2020-03-25 10:10:30 -04:00
Dave Bartolomeo
376779421d Merge pull request #2975 from rdmarsh2/printir-generate-all
C++/C#: generate IR for funcs excluded in PrintIR
2020-03-25 09:45:02 -04:00
Jonas Jensen
2b2667aef7 Merge remote-tracking branch 'upstream/master' into detect-conflated-memory
Conflicts:
	cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/IRSanity.qll
	cpp/ql/src/semmle/code/cpp/ir/implementation/raw/IRSanity.qll
	cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/IRSanity.qll
	cpp/ql/test/library-tests/ir/ir/aliased_ssa_sanity.expected
	cpp/ql/test/library-tests/ir/ir/aliased_ssa_sanity_unsound.expected
	cpp/ql/test/library-tests/ir/ir/raw_sanity.expected
	cpp/ql/test/library-tests/ir/ir/unaliased_ssa_sanity.expected
	cpp/ql/test/library-tests/ir/ir/unaliased_ssa_sanity_unsound.expected
	cpp/ql/test/library-tests/ir/ssa/aliased_ssa_sanity.expected
	cpp/ql/test/library-tests/ir/ssa/aliased_ssa_sanity_unsound.expected
	cpp/ql/test/library-tests/ir/ssa/unaliased_ssa_sanity.expected
	cpp/ql/test/library-tests/ir/ssa/unaliased_ssa_sanity_unsound.expected
	cpp/ql/test/library-tests/syntax-zoo/aliased_ssa_sanity.expected
	cpp/ql/test/library-tests/syntax-zoo/raw_sanity.expected
	cpp/ql/test/library-tests/syntax-zoo/unaliased_ssa_sanity.expected
	csharp/ql/src/semmle/code/csharp/ir/implementation/raw/IRSanity.qll
	csharp/ql/src/semmle/code/csharp/ir/implementation/unaliased_ssa/IRSanity.qll
	csharp/ql/test/library-tests/ir/ir/raw_ir_sanity.expected
	csharp/ql/test/library-tests/ir/ir/unaliased_ssa_sanity.expected
2020-03-25 11:55:39 +01:00
Mathias Vorreiter Pedersen
f92dd3c565 C++: Autoformat 2020-03-24 22:28:55 +01:00
Mathias Vorreiter Pedersen
077c282cd3 C++: Add field flow and accept tests 2020-03-24 22:28:54 +01:00
Mathias Vorreiter Pedersen
a5f08e1ea6 C++: Split parameter node class into an explicit and implicit version 2020-03-24 22:28:54 +01:00
Mathias Vorreiter Pedersen
22381f3ee6 C++: Demonstrate amount of field flow already present 2020-03-24 22:28:54 +01:00
Jonas Jensen
8f419d1676 C++: Fix conflated-memory sanity query
I had included `InitializeNonLocal` in the recursion because it made
everything look better in the presence of a bug that's since been fixed.
Taking it out means the sanity test is again aligned with the old
`isChiForAllAliasedMemory`.
2020-03-24 16:46:59 +01:00
Jonas Jensen
4e588869d8 C++: Sync identical files 2020-03-24 16:46:42 +01:00
Jonas Jensen
27832148a9 C++: Phi-node conflation is not about vvars 2020-03-24 13:56:42 +01:00
Jonas Jensen
95a8dcb3fd C++: failing test for non-conflated escaped var 2020-03-24 13:31:08 +01:00
Dave Bartolomeo
bebf89fed5 C++: Accept test diffs
All changes look like real improvements.
2020-03-23 17:20:19 -04:00
Jonas Jensen
999051d20e C++: QLDoc terminology: object -> mem allocation 2020-03-23 20:32:47 +01:00
Dave Bartolomeo
c5ac357bfc C++/C#: Fix bad overlap sanity failures
`Instruction.getDefinitionOverlap()` depends on `SSAConstruction::getMemoryOperandDefinition()`, which in turn depends on `SSAConstruction::hasMemoryOperandDefinition()`. When the definition in question came from a `Chi` instruction, `hasMemoryOperandDefinition()` incorrectly bound `overlap` to the overlap relationship between the original (non-`Chi`) instruction and the use. The fix is to make use of the `actualDefLocation` parameter to `getDefinitionOrChiInstruction()`, which specifies the location for the result of the `Chi` in that case.
2020-03-23 14:57:41 -04:00
Jonas Jensen
b0d3c9ee6b C++: Fix getExtentOverlap for entire allocation 2020-03-23 19:49:39 +01:00
Dave Bartolomeo
a2741da8e2 C++/C#: Add sanity test for invalid overlap from getDefinitionOverlap()
The result of `getDefinitionOverlap()` should never be `MayPartiallyOverlap`, because if that were the case, we should have inserted as `Chi` instruction and hooked the definition up to that instead.

There are quite a few existing failures.
2020-03-23 14:37:06 -04:00
Anders Schack-Mulligen
f29f0f418f Dataflow: Exclude flow param-param flow through with identical params. 2020-03-23 17:27:53 +01:00
Jonas Jensen
13465921a3 Merge pull request #3092 from dbartol/dbartol/VarArgIR2_ElectricBoogaloo
C++: Better IR for varargs
2020-03-23 14:13:54 +01:00
Anders Schack-Mulligen
888c504f55 Merge pull request #2903 from hvitved/dataflow/performance
Data flow: Refactoring + performance improvements
2020-03-23 10:01:20 +01:00
Jonas Jensen
79d5b88e33 C++: Remove redundant case 2020-03-20 19:40:53 +01:00
Dave Bartolomeo
fb71f781a0 C++: Fix formatting 2020-03-20 14:23:58 -04:00
Robert Marsh
d529fedbad C++: accept extractor changes to IR 2020-03-20 11:00:54 -07:00
Jonas Jensen
f6f9afe462 C++: Implement Instruction.isResultConflated
This predicate replaces `isChiForAllAliasedMemory`, which was always
intended to be temporary. A test is added to `IRSanity.qll` to verify
that the new predicate corresponds exactly with (a fixed version of) the
old one.

The implementation of the new predicate,
`Cached::hasConflatedMemoryResult` in `SSAConstruction.qll`, is faster
to compute than the old `isChiForAllAliasedMemory` because it uses
information that's readily available during SSA construction.
2020-03-20 17:57:18 +01:00
Dave Bartolomeo
82e2816915 C++: Fix handling of std::va_list that is used as a function parameter
In the Unix ABI, `std::va_list` is defined as `typedef struct __va_list_tag { ... } va_list[1];`, which means that any `std::va_list` used as a function parameter decays to `struct __va_list_tag*`. Handling this actually made the QL code slightly cleaner. The only tricky bit is that we have to determine what type to use as the actual `va_list` type when loading, storing, or modifying a `std::va_list`. To do this, we look at the type of the argument to the `va_*` macro. A detailed QLDoc comment explains the details.

I added a test case for passing a `va_list` as an argument, and then manipulating that `va_list` in the callee.
2020-03-20 12:53:09 -04:00
Geoffrey White
bb2ce6e5d9 C++: More missing override tags. 2020-03-20 16:23:15 +00:00
Geoffrey White
ccf5e03fc8 C++: Autoformat. 2020-03-20 15:01:22 +00:00
Geoffrey White
9e117709bc C++: mustwrite = false. 2020-03-20 14:59:57 +00:00
Dave Bartolomeo
bf284514fc C++: Better IR for varargs
This PR changes the IR we generate for functions that accept a variable argument list. Rather than simply using `BuiltInOperationInstruction` to model the various `va_*` macros as mysterious function-like operations, we now model them in more detail. The intent is to enable better alias analysis and taint flow through varargs.

The `va_start` macro now generates a unary `VarArgsStart` instruction that takes the address of the ellipsis pseudo-parameter as its operand, and returns a value of type `std::va_list`. This value is then stored into the actual `std::va_list` variable via a regular `Store`.

The `va_arg` macro now loads the `std::va_list` argument, then emits a `VarArg` instruction on the result. This returns the address of the vararg argument to be loaded. That address is later used as the address operand of a regular `Load` to return the value of the argument. To model the side effect of moving to the next argument, we emit a `NextVarArg` instruction that takes the previous `std::va_list` value and returns an updated one, which is then stored back into the `std::va_list` variable.

The `va_end` macro just emits a `VarArgsEnd` unary instruction that takes the address of the `std::va_list` argument and does nothing, since `va_end` doesn't really do anything on most compiler implementations anyway.

The `va_copy` macro is just modeled as a plain copy.
2020-03-19 19:23:33 -04:00
Mathias Vorreiter Pedersen
67cb8525bf Merge pull request #3082 from dbartol/dbartol/VarArgIR
C++: Model varargs in IR, Part I
2020-03-19 18:05:46 +01:00
Geoffrey White
88193dd389 C++: .expected change (desirable). 2020-03-19 13:32:17 +00:00
Dave Bartolomeo
74f61dc148 C++: Fix formatting 2020-03-19 09:18:32 -04:00
Geoffrey White
b444383ed1 C++: Add 'override' specifiers where I missed them. 2020-03-19 13:09:37 +00:00
Robert Marsh
59a81d8445 C++: merge from master and accept test changes 2020-03-18 13:47:01 -07:00
Robert Marsh
a30954599d Merge pull request #3085 from jbj/inStaticInitializer-AggregateLiteral
C++: Manual magic in inStaticInitializer
2020-03-18 13:23:04 -07:00
Dave Bartolomeo
30d2b865c6 C++: Fix formatting 2020-03-18 14:06:28 -04:00
Geoffrey White
f32e84b1d0 C++: Autoformat. 2020-03-18 17:24:46 +00:00
Tom Hvitved
937924571c Data flow: Sync files 2020-03-18 18:16:27 +01:00
Geoffrey White
2e4e491ce8 Merge branch 'master' into sideeffect 2020-03-18 17:12:14 +00:00
Geoffrey White
6cc1c2341c C++: Add some SideEffect models. 2020-03-18 16:42:33 +00:00
Geoffrey White
935b8d96f8 C++: Offset .expected for cleaner diff. 2020-03-18 16:42:33 +00:00