SV.TAINTED.INDEX_ACCESSUnvalidated input in array indexingWhenever input is accepted from the user or the outside environment, it should be validated for type, length, format, and range before it is used. Until properly validated, the data is said to be tainted. The SV.TAINTED family of checkers looks for the use of tainted data in code. The SV.TAINTED.INDEX_ACCESS checker flags code that uses tainted data to access an array. Vulnerability and riskWhen input to code isn't validated properly, an attacker can craft the input in a form that isn't expected by the application. The receipt of unintended input can result in altered control flow, arbitrary resource control, and arbitrary code execution. With this sort of opportunity, an attacker could
Using values supplied by the user as an array index can lead to index out-of-bounds vulnerabilities. If the vulnerable function allows for the reading from or writing to arbitrary memory, it could lead to application instability or, with a carefully constructed attack, data disclosure vulnerabilities or code injection. Mitigation and preventionTo avoid tainted input errors:
Vulnerable code example1 void getSize() 2 { 3 unsigned num, size; 4 int i; 5 scanf("%u %u",&num, &size); 6 sizes[num - 1] = size; 7 8 } Klocwork produces an issue report at line 6 indicating that unvalidated integer 'num' received through a call to 'scanf' at line 5 can be used to access an array at line 6. In this case, the SV.TAINTED.INDEX_ACCESS checker flags potentially tainted data used to access an array, which could be exploited by a malicious user. Fixed code example1 void getSize() 2 { 3 unsigned num, size; 4 int i; 5 scanf("%u %u",&num, &size); 6 if (num > sizeof(sizes)/sizeof(*sizes)) return; 7 sizes[num - 1] = size; 8 9 } In the fixed example, integer 'num' is validated at line 6 before it's used to access the array. Related checkersExternal guidance
|