
...
This compliant solution defines the acceptable range for length
as [1, MAX_TABLE_LENGTH]
. The length
parameter is declared as size_t
, which is unsigned by definition. Consequently, it is not necessary to check length
for negative values (see INT01-C. Use rsizesize_t or sizersize_t for all integer values representing the size of an object).
Code Block | ||||
---|---|---|---|---|
| ||||
enum { MAX_TABLE_LENGTH = 256 }; char** create_table(void) { const char* const lenstr = getenv("TABLE_SIZE"); const size_t length = lenstr ? strtoul(lenstr, NULL, 10) : 0; if (length == 0 || length > MAX_TABLE_LENGTH) return NULL; /* Indicate error to caller */ const size_t table_size = length * sizeof(char *); char** const table = (char **)malloc(table_size); if (table == NULL) return NULL; /* Indicate error to caller */ /* Initialize table... */ return table; } |
...
Recommendation | Severity | Likelihood | Detectable | Remediation CostRepairable | Priority | Level |
---|---|---|---|---|---|---|
INT04-C | High | Probable | Yes | HighNo | P6P12 | L2L1 |
Automated Detection
Tool | Version | Checker | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Astrée |
| Supported by taint analysis | ||||||||||
CodeSonar |
| IO.TAINT.SIZE (general) | Tainted allocation size CodeSonar will track the tainted value, along with any limits applied to it, and flag any problems caused by underconstraint. Warnings of a wide range of classes may be triggered, including tainted allocation size, buffer overrun, and division by zero | |||||||||
KlocworkHelix QAC |
Klocwork_V |
| DF2794, DF2804, DF2854, DF2859, DF2864, DF2894, DF2899, DF2904, DF2909, DF2914, DF2924, DF2944, DF2949, DF2954, DF2956, DF2959 | |||||||||
Klocwork |
| SV.TAINTED.ALLOC_SIZE SV.TAINTED.ALLOC_SIZE SV.TAINTED.BINOP SV.TAINTED.CALL.BINOP SV.TAINTED.CALL.INDEX_ACCESS SV.TAINTED.CALL.LOOP_BOUND SV.TAINTED.INDEX_ACCESS SV.TAINTED.LOOP_BOUND | ||||||||||
Parasoft C/C++test | 9.5 | BD-SECURITY-INTOVERF, BD-SECURITY-OVERFRD, BD-SECURITY-OVERFWR |
| CERT_C-INT04-a | Avoid potential integer overflow/underflow on tainted data | |||||||
Polyspace Bug Finder |
| Checks for:
| Polyspace Bug Finder | R2016a
Loop controlled by a value from an unsecure source Size argument to memory function is from an unsecure source Size of the variable-length array (VLA) is from an unsecure source and may be zero, negative, or too largeRec. partially supported. |
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
...