@@ -312,9 +312,30 @@ abstract class ContainerAccess extends VariableAccess { |
312 | 312 | abstract Variable getOwningContainer(); |
313 | 313 | } |
314 | 314 |
|
315 | | -pragma[noinline, nomagic] |
316 | | -private predicate localTaint(DataFlow::Node n1, DataFlow::Node n2) { |
317 | | - TaintTracking::localTaint(n1, n2) |
| 315 | +pragma[nomagic] |
| 316 | +private predicate containerTaintSource(FunctionCall fc, DataFlow::Node n1) { |
| 317 | + n1 = DataFlow::exprNode(fc) and |
| 318 | + exists(STLContainer c | |
| 319 | + fc = c.getACallToAFunction() and |
| 320 | + // There are a few cases where the value is tainted |
| 321 | + // but no actual link to the underlying container is established. |
| 322 | + // For example, calling Vector<int>.size() returns an int but the |
| 323 | + // resulting variable doesn't depend on the underlying container |
| 324 | + // anymore. |
| 325 | + ( |
| 326 | + fc.getTarget().getType() instanceof ReferenceType or |
| 327 | + fc.getTarget().getType() instanceof PointerType or |
| 328 | + fc.getTarget().getType() instanceof IteratorType |
| 329 | + ) |
| 330 | + ) |
| 331 | +} |
| 332 | + |
| 333 | +pragma[nomagic] |
| 334 | +private predicate containerTaint(FunctionCall fc, DataFlow::Node n2) { |
| 335 | + exists(DataFlow::Node n1 | |
| 336 | + containerTaintSource(fc, n1) and |
| 337 | + TaintTracking::localTaint(n1, n2) |
| 338 | + ) |
318 | 339 | } |
319 | 340 |
|
320 | 341 | /** |
@@ -326,19 +347,8 @@ class ContainerPointerOrReferenceAccess extends ContainerAccess { |
326 | 347 | Variable owningContainer; |
327 | 348 |
|
328 | 349 | ContainerPointerOrReferenceAccess() { |
329 | | - exists(STLContainer c, FunctionCall fc | |
330 | | - fc = c.getACallToAFunction() and |
331 | | - // There are a few cases where the value is tainted |
332 | | - // but no actual link to the underlying container is established. |
333 | | - // For example, calling Vector<int>.size() returns an int but the |
334 | | - // resulting variable doesn't depend on the underlying container |
335 | | - // anymore. |
336 | | - ( |
337 | | - fc.getTarget().getType() instanceof ReferenceType or |
338 | | - fc.getTarget().getType() instanceof PointerType or |
339 | | - fc.getTarget().getType() instanceof IteratorType |
340 | | - ) and |
341 | | - localTaint(DataFlow::exprNode(fc), DataFlow::exprNode(this)) and |
| 350 | + exists(FunctionCall fc | |
| 351 | + containerTaint(fc, DataFlow::exprNode(this)) and |
342 | 352 | (getUnderlyingType() instanceof ReferenceType or getUnderlyingType() instanceof PointerType) and |
343 | 353 | fc.getQualifier().(VariableAccess).getTarget() = owningContainer and |
344 | 354 | // Exclude cases where we see taint into the owning container |
|