Skip to content

Commit 1c1d264

Browse files
committed
First pass converting qlref tests to inline expectation with postprocess
1 parent 8d456df commit 1c1d264

420 files changed

Lines changed: 2847 additions & 2599 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
query: experimental/quantum/Examples/ReusedNonce.ql
2-
postprocess: utils/test/PrettyPrintModels.ql
2+
postprocess:
3+
- utils/test/PrettyPrintModels.ql
4+
- utils/test/InlineExpectationsTestQuery.ql

java/ql/test/experimental/query-tests/quantum/examples/NonceReuse/Test.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static SecretKey generateAESKey() throws Exception {
1616

1717
private static byte[] getRandomWrapper1() throws Exception {
1818
byte[] val = new byte[16];
19-
new SecureRandom().nextBytes(val);
19+
new SecureRandom().nextBytes(val); // $ Source
2020
return val;
2121
}
2222

@@ -37,7 +37,7 @@ private static void funcA1(byte[] iv) throws Exception {
3737
IvParameterSpec ivSpec = new IvParameterSpec(iv);
3838
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
3939
SecretKey key = generateAESKey();
40-
cipher.init(Cipher.ENCRYPT_MODE, key, ivSpec); // BAD: Reuse of `iv` in funcB1
40+
cipher.init(Cipher.ENCRYPT_MODE, key, ivSpec); // $ Alert // BAD: Reuse of `iv` in funcB1
4141
byte[] ciphertext = cipher.doFinal("Simple Test Data".getBytes());
4242
}
4343

@@ -46,7 +46,7 @@ private static void funcB1() throws Exception {
4646
IvParameterSpec ivSpec = new IvParameterSpec(iv);
4747
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
4848
SecretKey key = generateAESKey();
49-
cipher.init(Cipher.ENCRYPT_MODE, key, ivSpec); // BAD: Reuse of `iv` in funcA1
49+
cipher.init(Cipher.ENCRYPT_MODE, key, ivSpec); // $ Alert // BAD: Reuse of `iv` in funcA1
5050
byte[] ciphertext = cipher.doFinal("Simple Test Data".getBytes());
5151
}
5252

@@ -73,13 +73,13 @@ private static void funcA3() throws Exception {
7373
IvParameterSpec ivSpec1 = new IvParameterSpec(iv);
7474
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
7575
SecretKey key1 = generateAESKey();
76-
cipher.init(Cipher.ENCRYPT_MODE, key1, ivSpec1); // BAD: reuse of `iv` below
76+
cipher.init(Cipher.ENCRYPT_MODE, key1, ivSpec1); // $ Alert // BAD: reuse of `iv` below
7777
byte[] ciphertext = cipher.doFinal("Simple Test Data".getBytes());
7878

7979
IvParameterSpec ivSpec2 = new IvParameterSpec(iv);
8080
Cipher cipher2 = Cipher.getInstance("AES/CBC/PKCS5Padding");
8181
SecretKey key2 = generateAESKey();
82-
cipher2.init(Cipher.ENCRYPT_MODE, key2, ivSpec2); // BAD: Reuse of `iv` above
82+
cipher2.init(Cipher.ENCRYPT_MODE, key2, ivSpec2); // $ Alert // BAD: Reuse of `iv` above
8383
byte[] ciphertext2 = cipher2.doFinal("Simple Test Data".getBytes());
8484
}
8585

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
query: experimental/Security/CWE/CWE-020/Log4jJndiInjection.ql
2-
postprocess: utils/test/PrettyPrintModels.ql
2+
postprocess:
3+
- utils/test/PrettyPrintModels.ql
4+
- utils/test/InlineExpectationsTestQuery.ql

java/ql/test/experimental/query-tests/security/CWE-020/Log4jJndiInjectionTest.java

Lines changed: 1048 additions & 1048 deletions
Large diffs are not rendered by default.

java/ql/test/experimental/query-tests/security/CWE-073/FilePathInjection.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ public class FilePathInjection extends Controller {
1818

1919
// BAD: Upload file to user specified path without validation
2020
public void uploadFile() throws IOException {
21-
String savePath = getPara("dir");
21+
String savePath = getPara("dir"); // $ Source
2222
File file = getFile("fileParam").getFile();
2323
String finalFilePath = BASE_PATH + savePath;
2424

2525
FileInputStream fis = new FileInputStream(file);
26-
FileOutputStream fos = new FileOutputStream(finalFilePath);
26+
FileOutputStream fos = new FileOutputStream(finalFilePath); // $ Alert
2727
int i = 0;
2828

2929
do {
@@ -61,15 +61,15 @@ public void uploadFile2() throws IOException {
6161

6262
// BAD: Upload file to user specified path without validation through session attribute
6363
public void uploadFile3() throws IOException {
64-
String savePath = getPara("dir");
64+
String savePath = getPara("dir"); // $ Source
6565
setSessionAttr("uploadDir", savePath);
6666
String sessionUploadDir = getSessionAttr("uploadDir");
6767

6868
File file = getFile("fileParam").getFile();
6969
String finalFilePath = BASE_PATH + sessionUploadDir;
7070

7171
FileInputStream fis = new FileInputStream(file);
72-
FileOutputStream fos = new FileOutputStream(finalFilePath);
72+
FileOutputStream fos = new FileOutputStream(finalFilePath); // $ Alert
7373
int i = 0;
7474

7575
do {
@@ -84,15 +84,15 @@ public void uploadFile3() throws IOException {
8484

8585
// BAD: Upload file to user specified path without validation through request attribute
8686
public void uploadFile4() throws IOException {
87-
String savePath = getPara("dir");
87+
String savePath = getPara("dir"); // $ Source
8888
setAttr("uploadDir2", savePath);
8989
String requestUploadDir = getAttr("uploadDir2");
9090

9191
File file = getFile("fileParam").getFile();
9292
String finalFilePath = BASE_PATH + requestUploadDir;
9393

9494
FileInputStream fis = new FileInputStream(file);
95-
FileOutputStream fos = new FileOutputStream(finalFilePath);
95+
FileOutputStream fos = new FileOutputStream(finalFilePath); // $ Alert
9696
int i = 0;
9797

9898
do {
@@ -179,7 +179,7 @@ private void readFile(HttpServletResponse resp, File file) {
179179
FileInputStream fis = null;
180180
try {
181181
os = resp.getOutputStream();
182-
fis = new FileInputStream(file);
182+
fis = new FileInputStream(file); // $ Alert
183183
byte fileContent[] = new byte[(int) file.length()];
184184
fis.read(fileContent);
185185
os.write(fileContent);
@@ -202,12 +202,12 @@ private void readFile(HttpServletResponse resp, File file) {
202202
// BAD: Download file to user specified path without validation
203203
public void downloadFile() throws FileNotFoundException, IOException {
204204
HttpServletRequest request = getRequest();
205-
String path = request.getParameter("path");
205+
String path = request.getParameter("path"); // $ Source
206206
String filePath = BASE_PATH + path;
207207

208208
HttpServletResponse resp = getResponse();
209209
File file = new File(filePath);
210-
if (path != null && file.exists()) {
210+
if (path != null && file.exists()) { // $ Alert
211211
resp.setHeader("Content-type", "application/force-download");
212212
resp.setHeader("Content-Disposition", "inline;filename=\"" + filePath + "\"");
213213
resp.setHeader("Content-Transfer-Encoding", "Binary");
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
query: experimental/Security/CWE/CWE-073/FilePathInjection.ql
2-
postprocess: utils/test/PrettyPrintModels.ql
2+
postprocess:
3+
- utils/test/PrettyPrintModels.ql
4+
- utils/test/InlineExpectationsTestQuery.ql
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
query: experimental/Security/CWE/CWE-078/CommandInjectionRuntimeExecLocal.ql
2-
postprocess: utils/test/PrettyPrintModels.ql
2+
postprocess:
3+
- utils/test/PrettyPrintModels.ql
4+
- utils/test/InlineExpectationsTestQuery.ql
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
query: experimental/Security/CWE/CWE-078/ExecTainted.ql
2-
postprocess: utils/test/PrettyPrintModels.ql
2+
postprocess:
3+
- utils/test/PrettyPrintModels.ql
4+
- utils/test/InlineExpectationsTestQuery.ql

java/ql/test/experimental/query-tests/security/CWE-078/JSchOSInjectionTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
1111
String host = "sshHost";
1212
String user = "user";
1313
String password = "password";
14-
String command = request.getParameter("command");
14+
String command = request.getParameter("command"); // $ Source[java/command-line-injection-experimental]
1515

1616
java.util.Properties config = new java.util.Properties();
1717
config.put("StrictHostKeyChecking", "no");
@@ -24,7 +24,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
2424
session.connect();
2525

2626
Channel channel = session.openChannel("exec");
27-
((ChannelExec) channel).setCommand("ping " + command);
27+
((ChannelExec) channel).setCommand("ping " + command); // $ Alert[java/command-line-injection-experimental]
2828
channel.setInputStream(null);
2929
((ChannelExec) channel).setErrStream(System.err);
3030

@@ -37,7 +37,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
3737
String host = "sshHost";
3838
String user = "user";
3939
String password = "password";
40-
String command = request.getParameter("command");
40+
String command = request.getParameter("command"); // $ Source[java/command-line-injection-experimental]
4141

4242
java.util.Properties config = new java.util.Properties();
4343
config.put("StrictHostKeyChecking", "no");
@@ -50,7 +50,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
5050
session.connect();
5151

5252
ChannelExec channel = (ChannelExec)session.openChannel("exec");
53-
channel.setCommand("ping " + command);
53+
channel.setCommand("ping " + command); // $ Alert[java/command-line-injection-experimental]
5454
channel.setInputStream(null);
5555
channel.setErrStream(System.err);
5656

java/ql/test/experimental/query-tests/security/CWE-078/RuntimeExecTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,29 @@ public class RuntimeExecTest {
1414
public static void test() {
1515
System.out.println("Command injection test");
1616

17-
String script = System.getenv("SCRIPTNAME");
17+
String script = System.getenv("SCRIPTNAME"); // $ Source[java/command-line-injection-extra-local]
1818

1919
if (script != null) {
2020
try {
2121
// 1. array literal in the args
22-
Runtime.getRuntime().exec(new String[]{"/bin/sh", script});
22+
Runtime.getRuntime().exec(new String[]{"/bin/sh", script}); // $ Alert[java/command-line-injection-extra-local]
2323

2424
// 2. array literal with dataflow
2525
String[] commandArray1 = new String[]{"/bin/sh", script};
26-
Runtime.getRuntime().exec(commandArray1);
26+
Runtime.getRuntime().exec(commandArray1); // $ Alert[java/command-line-injection-extra-local]
2727

2828
// 3. array assignment after it is created
2929
String[] commandArray2 = new String[4];
3030
commandArray2[0] = "/bin/sh";
3131
commandArray2[1] = script;
32-
Runtime.getRuntime().exec(commandArray2);
32+
Runtime.getRuntime().exec(commandArray2); // $ Alert[java/command-line-injection-extra-local]
3333

3434
// 4. Stream concatenation
3535
Runtime.getRuntime().exec(
36-
Stream.concat(
36+
Stream.concat( // $
3737
Arrays.stream(new String[]{"/bin/sh"}),
3838
Arrays.stream(new String[]{script})
39-
).toArray(String[]::new)
39+
).toArray(String[]::new) // $ Alert[java/command-line-injection-extra-local]
4040
);
4141

4242
} catch (Exception e) {

0 commit comments

Comments
 (0)