Subhranil Sengupta
Subhranil Sengupta

Reputation: 119

How to handle CWE-400-Resource exhaustion error

We are getting an IBM APPSCAN exception for the following code.

{
    br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
}
StringBuilder sb = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
    sb.append(line+"\n");
}
br.close(); 

Can someone suggest a way to handle the same.

Upvotes: 0

Views: 769

Answers (1)

Subhranil Sengupta
Subhranil Sengupta

Reputation: 119

I myself have figured out the solution for this.

Just we need to limit the character read by readline(). there is no way to limit the same, so we need to use BoundedBufferedReader.

Try the below:

{
    br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
}
StringBuilder sb = new StringBuilder();
String line;
BoundedBufferedReader boundedReader = new BoundedBufferedReader(br,204800,204800);
                   while (( line = boundedReader.readLine() ) != null) {
                       sb.append(line+"\n");
                   }
br.close();

Upvotes: 1

Related Questions