Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The compliant solution also uses the File.getCanonicalFile() method to canonicalize the file to simplify subsequent path name comparisons (see rule IDS02-J. Canonicalize path names before validating them for more information).)

Code Block
bgColor#ccccff
class ExceptionExample {
  public static void main(String[] args) {

    File file = null;
    try {
      file = new File(System.getenv("APPDATA") +
             args[0]).getCanonicalFile();
      if (!file.getPath().startsWith("c:\\homepath")) {
        System.out.println("Invalid file");
        return;
      }
    } catch (IOException x) {
      System.out.println("Invalid file");
      return;
    }

    try {
      FileInputStream fis = new FileInputStream(file);
    } catch (FileNotFoundException x) {
      System.out.println("Invalid file");
      return;
    }
  }
}

...

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="63fa9d667c7a9e30-f06a00c1-46b2424f-a1b2a76b-774cca5cae2dc81ee257b83e"><ac:plain-text-body><![CDATA[

[[Gong 2003

AA. Bibliography#Gong 03]]

9.1, Security Exceptions

]]></ac:plain-text-body></ac:structured-macro>

...