Difference between revisions of "Cpp Coding Standards/SECURITY/IntOver"
From Apache OpenOffice Wiki
| Line 11: | Line 11: | ||
*Triple-check any integer-related compiler warnings, and any cast operations that silence them. | *Triple-check any integer-related compiler warnings, and any cast operations that silence them. | ||
| + | |||
| + | *Be aware of the [http://blogs.msdn.com/oldnewthing/archive/2004/01/29/64389.aspx implicit buffer overflows] in new[] operator. | ||
See also [http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncode/html/secure04102003.asp Reviewing Code for Integer Manipulation Vulnerabilities]. | See also [http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncode/html/secure04102003.asp Reviewing Code for Integer Manipulation Vulnerabilities]. | ||
Revision as of 09:35, 18 January 2007
Be aware that integers have limited range – not properly checking valid input ranges before doing integer arithmetic, or assigning to other integer types of insufficient range, will lead to overflows. Often, integer overflows can be used as an attack vector to launch a subsequent buffer overflow, with the fatal consequences outlined in SECURITY:NoBufferOverflow.
Hints:
- Read and understand this background article on integer overflows.
- Generally, use sal_Size for buffer sizes and counts. There is usually no reason to use a signed value here (but watch out for assignments and comparisons with signed types).
- If you perform integer arithmetic, and the result is used to index arrays, calculate sizes, or as a parameter to array-new, make sure the operands fall into a safe, and well-understood range (check before you perform the calculation)
- Be extremely careful not to pass signed integers to memory allocation functions (new, alloca, rtl_allocateMemory), as they are interpreted as unsigned integers.
- Triple-check any integer-related compiler warnings, and any cast operations that silence them.
- Be aware of the implicit buffer overflows in new[] operator.
See also Reviewing Code for Integer Manipulation Vulnerabilities.