範例 3:不同的來源和接收槽檔案

下列範例說明與接收槽不同檔案的來源。

TestCase_IOT_Xfile_Part1.java

public class TestCase_IOT_XFile_Part1 {
	public static void main(String[] args) {
		try {
			TestCase_IOT_XFile_Part1 testCase =
				new TestCase_IOT_XFile_Part1();
			TestCase_IOT_XFile_Part2 testCase2 =
				new TestCase_IOT_XFile_Part2();
			testCase2.writeToVulnerableSink(
				testCase.getVulnerableSource(args[0]));
		} catch (Exception e) {
		}
	}

	public String getVulnerableSource(String file)
		throws IOException, FileNotFoundException {
		FileInputStream fis = new FileInputStream(file);
		byte[] buf = new byte[100];
		fis.read(buf);
		String ret = new String(buf);
		fis.close();
		return ret;
	}
}

TestCase_IOT_Xfile_Part2.java

public class TestCase_IOT_XFile_Part2 {
	public void writeToVulnerableSink(String str)
		throws FileNotFoundException {
		FileOutputStream fos = new FileOutputStream(str);
		PrintWriter writer = new PrintWriter(fos);
		writer.write(str);
	}
}

追蹤從 TestCase_IOT_Xfile_Part1.javaTestCase_IOT_Xfile_Part2.java 的資料可追蹤整個程式內的資料流。堆疊追蹤呈現如下:


「追蹤」視圖,顯示從 TestCase_IOT_XFile_Part1 到 TestCase_IOT_XFile_Part2 的資料流

這個範例顯示經過 main 方法從 TestCase_IOT_XFile_Part1TestCase_IOT_XFile_Part2 的資料流。