JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.
If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.
If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.
| CodeSonar® 9.2p0 | CONFIDENTIAL | CodeSecure Inc |
An allocation size used as an argument to an allocator function is based on unchecked multiplication, thus risking integer overflow and an unexpectedly small allocated block.
In general, this class represents a subset of Multiplication Overflow of Allocation Size, except that the implicit multiplication in C++ new[] may trigger an Integer Overflow Of Allocation Size warning but will not trigger a Multiplication Overflow of Allocation Size warning.
| Class Name | Integer Overflow of Allocation Size | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Significance | security | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Mnemonic | ALLOC.SIZE.IOFLOW | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Categories |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Availability | Available for C and C++. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Enabling | Checks for this warning class are enabled by
default. To disable them, add the following WARNING_FILTER rule to the
project configuration file.
WARNING_FILTER += discard class="Integer Overflow of Allocation Size" |
To avoid Integer Overflow of Allocation Size warnings, check the result of any multiplication operation before using it to compute an allocation size.
#include <cstdlib>
void ioflow(int x, int y, int z){
int s;
char *p;
p = (char *) malloc(x * y); /* 'Integer Overflow of Allocation Size' warning issued here */
/* When enabled, 'Multiplication Overflow of Allocation Size' warning also issued here */
if (!p){return;} else {free(p);}
s = x * y;
p = (char *) malloc(s); /* 'Integer Overflow of Allocation Size' warning issued here */
if (!p){return;} else {free(p);}
p = new char[x * y]; /* 'Integer Overflow of Allocation Size' warning issued here */
delete[] p;
s = y * z;
if (s / y == z){
p = (char *) malloc(s + 1); /* ok: multiplication result was checked */
if (!p){return;} else {free(p);}
}
if ( (y*z) / y == z){
p = (char *) malloc(y*z + 1); /* 'Integer Overflow of Allocation Size' warning issued here
* - the multiplication operation inside the malloc() argument was not checked
*/
if (!p){return;} else {free(p);}
}
}
The following configuration file parameters affect checks for this warning class.
To report problems with this documentation, please visit https://support.codesecure.com/.