From 33f6392be5c73f91d0e480fbedab1ffda44cd833 Mon Sep 17 00:00:00 2001 From: Anders Schack-Mulligen Date: Thu, 27 Feb 2020 10:47:25 +0100 Subject: [PATCH] Java: Add some more taint-getter-setter tests. --- .../dataflow/taintgettersetter/A.java | 34 +++++++++++++++++++ .../taintgettersetter.expected | 4 +++ 2 files changed, 38 insertions(+) diff --git a/java/ql/test/library-tests/dataflow/taintgettersetter/A.java b/java/ql/test/library-tests/dataflow/taintgettersetter/A.java index 7128072977a..b92128981c8 100644 --- a/java/ql/test/library-tests/dataflow/taintgettersetter/A.java +++ b/java/ql/test/library-tests/dataflow/taintgettersetter/A.java @@ -34,4 +34,38 @@ public class A { Box b4 = Box.mk(taint()); sink(b4.getS1()); } + + static class Box2 { + String s; + String getS() { return s; } + void setS(String s) { this.s = s; } + + Box2(String s) { + setS(s + "1"); + } + String getS1() { return getS() + "2"; } + String getS2() { return step(getS() + "_") + "2"; } + void setS1(String s) { setS("3" + s); } + void setS2(String s) { setS("3" + step("_" + s)); } + static Box2 mk(String s) { + Box2 b = new Box2(""); + b.setS(step(s)); + return b; + } + } + + void foo2(Box2 b1, Box2 b2) { + b1.setS1(taint()); + sink(b1.getS1()); + + b2.setS2(taint()); + sink(b2.getS2()); + + String t3 = taint(); + Box2 b3 = new Box2(step(t3)); + sink(b3.s); + + Box2 b4 = Box2.mk(taint()); + sink(b4.getS1()); + } } diff --git a/java/ql/test/library-tests/dataflow/taintgettersetter/taintgettersetter.expected b/java/ql/test/library-tests/dataflow/taintgettersetter/taintgettersetter.expected index 6eb9d3aa505..0617ef3ede7 100644 --- a/java/ql/test/library-tests/dataflow/taintgettersetter/taintgettersetter.expected +++ b/java/ql/test/library-tests/dataflow/taintgettersetter/taintgettersetter.expected @@ -2,3 +2,7 @@ | A.java:27:14:27:20 | taint(...) | A.java:28:10:28:19 | getS2(...) | | A.java:30:17:30:23 | taint(...) | A.java:32:10:32:13 | b3.s | | A.java:34:21:34:27 | taint(...) | A.java:35:10:35:19 | getS1(...) | +| A.java:58:14:58:20 | taint(...) | A.java:59:10:59:19 | getS1(...) | +| A.java:61:14:61:20 | taint(...) | A.java:62:10:62:19 | getS2(...) | +| A.java:64:17:64:23 | taint(...) | A.java:66:10:66:13 | b3.s | +| A.java:68:23:68:29 | taint(...) | A.java:69:10:69:19 | getS1(...) |