77
88public class PartialPathTraversalTest {
99 public void esapiExample (File dir , File parent ) throws IOException {
10- if (!dir .getCanonicalPath ().startsWith (parent .getCanonicalPath ())) {
10+ if (!dir .getCanonicalPath ().startsWith (parent .getCanonicalPath ())) { // $hasTaintFlow
1111 throw new IOException ("Invalid directory: " + dir .getCanonicalPath ());
1212 }
1313 }
1414
1515 @ SuppressWarnings ("ResultOfMethodCallIgnored" )
1616 void foo1 (File dir , File parent ) throws IOException {
17- (dir .getCanonicalPath ()).startsWith ((parent .getCanonicalPath ()));
17+ (dir .getCanonicalPath ()).startsWith ((parent .getCanonicalPath ())); // $hasTaintFlow
1818 }
1919
2020 void foo2 (File dir , File parent ) throws IOException {
@@ -26,42 +26,42 @@ void foo2(File dir, File parent) throws IOException {
2626
2727 void foo3 (File dir , File parent ) throws IOException {
2828 String parentPath = parent .getCanonicalPath ();
29- if (!dir .getCanonicalPath ().startsWith (parentPath )) {
29+ if (!dir .getCanonicalPath ().startsWith (parentPath )) { // $hasTaintFlow
3030 throw new IOException ("Invalid directory: " + dir .getCanonicalPath ());
3131 }
3232 }
3333
3434 void foo4 (File dir ) throws IOException {
35- if (!dir .getCanonicalPath ().startsWith ("/usr" + "/dir" )) {
35+ if (!dir .getCanonicalPath ().startsWith ("/usr" + "/dir" )) { // $hasTaintFlow
3636 throw new IOException ("Invalid directory: " + dir .getCanonicalPath ());
3737 }
3838 }
3939
4040 void foo5 (File dir , File parent ) throws IOException {
4141 String canonicalPath = dir .getCanonicalPath ();
42- if (!canonicalPath .startsWith (parent .getCanonicalPath ())) {
42+ if (!canonicalPath .startsWith (parent .getCanonicalPath ())) { // $hasTaintFlow
4343 throw new IOException ("Invalid directory: " + dir .getCanonicalPath ());
4444 }
4545 }
4646
4747 void foo6 (File dir , File parent ) throws IOException {
4848 String canonicalPath = dir .getCanonicalPath ();
49- if (!canonicalPath .startsWith (parent .getCanonicalPath ())) {
49+ if (!canonicalPath .startsWith (parent .getCanonicalPath ())) { // $hasTaintFlow
5050 throw new IOException ("Invalid directory: " + dir .getCanonicalPath ());
5151 }
5252 String canonicalPath2 = dir .getCanonicalPath ();
53- if (!canonicalPath2 .startsWith (parent .getCanonicalPath ())) {
53+ if (!canonicalPath2 .startsWith (parent .getCanonicalPath ())) { // $hasTaintFlow
5454 throw new IOException ("Invalid directory: " + dir .getCanonicalPath ());
5555 }
5656 }
5757
5858 void foo7 (File dir , File parent ) throws IOException {
5959 String canonicalPath = dir .getCanonicalPath ();
6060 String canonicalPath2 = dir .getCanonicalPath ();
61- if (!canonicalPath .startsWith (parent .getCanonicalPath ())) {
61+ if (!canonicalPath .startsWith (parent .getCanonicalPath ())) { // $hasTaintFlow
6262 throw new IOException ("Invalid directory: " + dir .getCanonicalPath ());
6363 }
64- if (!canonicalPath2 .startsWith (parent .getCanonicalPath ())) {
64+ if (!canonicalPath2 .startsWith (parent .getCanonicalPath ())) { // $hasTaintFlow
6565 throw new IOException ("Invalid directory: " + dir .getCanonicalPath ());
6666 }
6767 }
@@ -72,7 +72,7 @@ File getChild() {
7272
7373 void foo8 (File parent ) throws IOException {
7474 String canonicalPath = getChild ().getCanonicalPath ();
75- if (!canonicalPath .startsWith (parent .getCanonicalPath ())) {
75+ if (!canonicalPath .startsWith (parent .getCanonicalPath ())) {
7676 throw new IOException ("Invalid directory: " + getChild ().getCanonicalPath ());
7777 }
7878 }
@@ -91,18 +91,18 @@ void foo10(File dir, File parent) throws IOException {
9191
9292 void foo11 (File dir , File parent ) throws IOException {
9393 String parentCanonical = parent .getCanonicalPath ();
94- if (!dir .getCanonicalPath ().startsWith (parentCanonical )) {
94+ if (!dir .getCanonicalPath ().startsWith (parentCanonical )) { // $hasTaintFlow
9595 throw new IOException ("Invalid directory: " + dir .getCanonicalPath ());
9696 }
9797 }
9898
9999 void foo12 (File dir , File parent ) throws IOException {
100100 String parentCanonical = parent .getCanonicalPath ();
101101 String parentCanonical2 = parent .getCanonicalPath ();
102- if (!dir .getCanonicalPath ().startsWith (parentCanonical )) {
102+ if (!dir .getCanonicalPath ().startsWith (parentCanonical )) { // $hasTaintFlow
103103 throw new IOException ("Invalid directory: " + dir .getCanonicalPath ());
104104 }
105- if (!dir .getCanonicalPath ().startsWith (parentCanonical2 )) {
105+ if (!dir .getCanonicalPath ().startsWith (parentCanonical2 )) { // $hasTaintFlow
106106 throw new IOException ("Invalid directory: " + dir .getCanonicalPath ());
107107 }
108108 }
@@ -116,7 +116,7 @@ void foo13(File dir, File parent) throws IOException {
116116
117117 void foo14 (File dir , File parent ) throws IOException {
118118 String parentCanonical = parent .getCanonicalPath () + separatorChar ;
119- if (!dir .getCanonicalPath ().startsWith (parentCanonical )) {
119+ if (!dir .getCanonicalPath ().startsWith (parentCanonical )) {
120120 throw new IOException ("Invalid directory: " + dir .getCanonicalPath ());
121121 }
122122 }
@@ -170,7 +170,7 @@ void foo18(File dir, File parent, boolean branch) throws IOException {
170170
171171 void foo19 (File dir , File parent ) throws IOException {
172172 String parentCanonical = parent .getCanonicalPath () + "/potato" ;
173- if (!dir .getCanonicalPath ().startsWith (parentCanonical )) {
173+ if (!dir .getCanonicalPath ().startsWith (parentCanonical )) { // $hasTaintFlow
174174 throw new IOException ("Invalid directory: " + dir .getCanonicalPath ());
175175 }
176176 }
@@ -188,7 +188,7 @@ InputStream foo20(String... path) {
188188 String filePath = sb .toString ();
189189 File encodedFile = new File (filePath );
190190 try {
191- if (!encodedFile .getCanonicalPath ().startsWith (cacheDir .getCanonicalPath ())) {
191+ if (!encodedFile .getCanonicalPath ().startsWith (cacheDir .getCanonicalPath ())) { // $hasTaintFlow
192192 return null ;
193193 }
194194 return Files .newInputStream (encodedFile .toPath ());
@@ -206,7 +206,7 @@ void foo21(File dir, File parent) throws IOException {
206206
207207 void foo22 (File dir , File dir2 , File parent , boolean conditional ) throws IOException {
208208 String canonicalPath = conditional ? dir .getCanonicalPath () : dir2 .getCanonicalPath ();
209- if (!canonicalPath .startsWith (parent .getCanonicalPath ())) {
209+ if (!canonicalPath .startsWith (parent .getCanonicalPath ())) { // $hasTaintFlow
210210 throw new IOException ("Invalid directory: " + dir .getCanonicalPath ());
211211 }
212212 }
0 commit comments