Versions Compared

Key

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

...

Code Block
bgColor#ccccff
class ReadNames {
  // ... other methods

  public static String readLimitedLine(ReaderBufferedReader reader, int limit) 
                                       throws IOException {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < limit; i++) {
      int c = reader.read();
      if (c == -1) {
        return null;
      }
      if (((char) c == '\n') || ((char) c == '\r')) {
        break;
      }
      sb.append((char) c);
    }
    return sb.toString();
  }

  public static final int lineLengthLimit = 1024;
  public static final int lineCountLimit = 1000000;

  public void addNames() throws IOException {
    try {
      String newName;
      for (int i = 0; i < lineCountLimit; i++) {
        newName = readLimitedLine(reader, lineLengthLimit);
        if (newName == null || newName.equalsIgnoreCase("quit")) {
          break;
        }
        names.addElement(newName);
        System.out.println("adding " + newName);
      }
    } finally {
      input.close();
    }
  }

}

...

CERT C Secure Coding Standard

MEM11-C. Do not assume infinite heap space

CERT C++ Secure Coding Standard

MEM12-CPP. Do not assume infinite heap space

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="4052803f84485a03-2bccda2f-4f084cfd-bf81822a-79e7c3d8ccd1f34482eea0ab"><ac:plain-text-body><![CDATA[

[ISO/IEC TR 24772:2010

http://www.aitcnet.org/isai/]

Resource Exhaustion [XZP]

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

MITRE CWE

CWE-400. Uncontrolled resource consumption ("resource exhaustion")

 

CWE-770. Allocation of resources without limits or throttling

...

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="d3493c59e98198a4-3ba22e1f-46f144b7-98f5b35e-0b27caa7fb6a520479c5f89e"><ac:plain-text-body><![CDATA[

[[API 2006

AA. References#API 06]]

Class ObjectInputStream and ObjectOutputStream

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

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="8afb441753e67892-2405cd59-4dd9410e-96f0b8aa-585673a7c8bfcae4e9fe58f9"><ac:plain-text-body><![CDATA[

[[Java 2006

AA. References#Java 06]]

[java – The Java application launcher

http://java.sun.com/javase/6/docs/technotes/tools/windows/java.html], Syntax for increasing the heap size

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

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="00be112b35837843-911d4f20-4b8545d0-b305a095-0c20c030c0e3fb50c75b8ccc"><ac:plain-text-body><![CDATA[

[[SDN 2008

AA. References#SDN 08]]

[Serialization FAQ

http://java.sun.com/javase/technologies/core/basic/serializationFAQ.jsp]

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

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="55f3a09f03bf7d50-9ca75896-4c734e3f-9609a347-820801efec443e92e77366a5"><ac:plain-text-body><![CDATA[

[[Sun 2003

AA. References#Sun 03]]

Chapter 5, Tuning the Java Runtime System, [Tuning the Java Heap

http://docs.sun.com/source/817-2180-10/pt_chap5.html#wp57027]

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

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="d4af468e421b2377-2774db0e-4b784e17-a0c782f0-c43e485202f1f8f71e2e77a8"><ac:plain-text-body><![CDATA[

[[Sun 2006

AA. References#Sun 06]]

[Garbage Collection Ergonomics

http://java.sun.com/javase/6/docs/technotes/guides/vm/gc-ergonomics.html ], Default values for the Initial and Maximum Heap Size

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

...