Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

SV.DOS.ARRINDEX

This error occurs when unvalidated user input is used as the index of an array or by methods that will use it as the index of an array.

Vulnerability and risk

When unvalidated user input is used as the index of an array or by methods that will use it as the index of an array, an attack can cause the methods to throw an ArrayOutOfBounds exception. This can then be used to cause Denial of Service or to manipulate the stated object to create an alternate control flow, which could be used to the advantage of the attacker. For example, if an error is printed, it might leak some information to the attacker. If an error occurred during authentication, it could create open-on-fail conditions, allowing the attacker to get an unauthorized session.

Klocwork security vulnerability (SV) checkers identify calls that create potentially dangerous data; these calls are considered unsafe sources. An unsafe source can be any data provided by the user, since the user could be an attacker or has the potential for introducing human error.

Mitigation and prevention

To prevent denial-of-service (DoS) attacks from user input, validate any and all input from outside the application (user input, file input, system parameters, and so on). Validation should include bounds validation using information from an appropriate, accessible container.

Example 1

16     protected synchronized void doPost(HttpServletRequest req, HttpServletResponse resp)
17             throws ServletException, IOException {
18         String indexString = req.getParameter("index");
19         final int index;
20         try {
21             index = Integer.parseInt(indexString);
22         } catch (NumberFormatException e) {
23             resp.sendError(505, "Internal Error");
24             return;
25         }
26 
27         String key = data[index];
28         resp.getOutputStream().println("Success! " + key);
29     }

SV.DOS.ARRINDEX is reported for line 27: 'indexString' contains a value coming from an HTTP request and thus can be tainted (line 18). On line 21 tainted 'indexString' is parsed and stored in 'index' which is used to access an array element on line 27. A potential attacker can specify a large number, leading to an ArrayOutOfBounds exception, which can damage the state of the application and lead to a DoS attack.

Extension

This checker can be extended through the Klocwork knowledge base. See Tuning Java analysis for more information.