mirror of
https://github.com/github/codeql.git
synced 2026-05-04 05:05:12 +02:00
Make reporting locations consistent with PathCreation; add test
This commit is contained in:
@@ -8,6 +8,7 @@ edges
|
||||
| Test.java:79:74:79:97 | getInputStream(...) : ServletInputStream | Test.java:79:52:79:98 | new InputStreamReader(...) : InputStreamReader |
|
||||
| Test.java:80:31:80:32 | br : BufferedReader | Test.java:80:31:80:43 | readLine(...) : String |
|
||||
| Test.java:80:31:80:43 | readLine(...) : String | Test.java:82:67:82:81 | ... + ... |
|
||||
| Test.java:88:17:88:37 | getHostName(...) : String | Test.java:90:26:90:29 | temp |
|
||||
nodes
|
||||
| Test.java:19:18:19:38 | getHostName(...) : String | semmle.label | getHostName(...) : String |
|
||||
| Test.java:24:20:24:23 | temp | semmle.label | temp |
|
||||
@@ -20,6 +21,8 @@ nodes
|
||||
| Test.java:80:31:80:32 | br : BufferedReader | semmle.label | br : BufferedReader |
|
||||
| Test.java:80:31:80:43 | readLine(...) : String | semmle.label | readLine(...) : String |
|
||||
| Test.java:82:67:82:81 | ... + ... | semmle.label | ... + ... |
|
||||
| Test.java:88:17:88:37 | getHostName(...) : String | semmle.label | getHostName(...) : String |
|
||||
| Test.java:90:26:90:29 | temp | semmle.label | temp |
|
||||
subpaths
|
||||
#select
|
||||
| Test.java:24:11:24:24 | new File(...) | Test.java:19:18:19:38 | getHostName(...) : String | Test.java:24:20:24:23 | temp | $@ flows to here and is used in a path. | Test.java:19:18:19:38 | getHostName(...) | User-provided value |
|
||||
@@ -27,3 +30,4 @@ subpaths
|
||||
| Test.java:30:11:30:48 | getPath(...) | Test.java:19:18:19:38 | getHostName(...) : String | Test.java:30:44:30:47 | temp | $@ flows to here and is used in a path. | Test.java:19:18:19:38 | getHostName(...) | User-provided value |
|
||||
| Test.java:34:12:34:25 | new File(...) | Test.java:19:18:19:38 | getHostName(...) : String | Test.java:34:21:34:24 | temp | $@ flows to here and is used in a path. | Test.java:19:18:19:38 | getHostName(...) | User-provided value |
|
||||
| Test.java:82:52:82:88 | new FileWriter(...) | Test.java:79:74:79:97 | getInputStream(...) : ServletInputStream | Test.java:82:67:82:81 | ... + ... | $@ flows to here and is used in a path. | Test.java:79:74:79:97 | getInputStream(...) | User-provided value |
|
||||
| Test.java:90:26:90:29 | temp | Test.java:88:17:88:37 | getHostName(...) : String | Test.java:90:26:90:29 | temp | $@ flows to here and is used in a path. | Test.java:88:17:88:37 | getHostName(...) | User-provided value |
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// http://cwe.mitre.org/data/definitions/22.html
|
||||
package test.cwe22.semmle.tests;
|
||||
|
||||
|
||||
import javax.servlet.http.*;
|
||||
import javax.servlet.ServletException;
|
||||
|
||||
@@ -12,6 +11,7 @@ import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.FileSystems;
|
||||
|
||||
import org.apache.commons.io.output.LockableFileWriter;
|
||||
|
||||
class Test {
|
||||
void doGet1(InetAddress address)
|
||||
@@ -19,13 +19,13 @@ class Test {
|
||||
String temp = address.getHostName();
|
||||
File file;
|
||||
Path path;
|
||||
|
||||
|
||||
// BAD: construct a file path with user input
|
||||
file = new File(temp);
|
||||
|
||||
|
||||
// BAD: construct a path with user input
|
||||
path = Paths.get(temp);
|
||||
|
||||
|
||||
// BAD: construct a path with user input
|
||||
path = FileSystems.getDefault().getPath(temp);
|
||||
|
||||
@@ -34,7 +34,7 @@ class Test {
|
||||
file = new File(temp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void doGet2(InetAddress address)
|
||||
throws IOException {
|
||||
String temp = address.getHostName();
|
||||
@@ -44,7 +44,7 @@ class Test {
|
||||
if(isSafe(temp))
|
||||
file = new File(temp);
|
||||
}
|
||||
|
||||
|
||||
void doGet3(InetAddress address)
|
||||
throws IOException {
|
||||
String temp = address.getHostName();
|
||||
@@ -66,7 +66,7 @@ class Test {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
boolean isSortOfSafe(String pathSpec) {
|
||||
// no file separators
|
||||
if (pathSpec.contains(File.separator))
|
||||
@@ -82,4 +82,11 @@ class Test {
|
||||
BufferedWriter bw = new BufferedWriter(new FileWriter("dir/"+filename, true));
|
||||
}
|
||||
}
|
||||
|
||||
void doGet4(InetAddress address)
|
||||
throws IOException {
|
||||
String temp = address.getHostName();
|
||||
// BAD: open a file based on user input, using a MaD-documented API
|
||||
new LockableFileWriter(temp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
// semmle-extractor-options: --javac-args -cp ${testdir}/../../../../../stubs/servlet-api-2.4
|
||||
// semmle-extractor-options: --javac-args -cp ${testdir}/../../../../../stubs/servlet-api-2.4:${testdir}/../../../../../stubs/apache-commons-io-2.6
|
||||
|
||||
Reference in New Issue
Block a user