According to the C Standard, subclause 7.4 [ISO/IEC 9899:2011],
The header
<ctype.h>
declares several functions useful for classifying and mapping characters. In all cases the argument is anint
, the value of which shall be representable as anunsigned char
or shall equal the value of the macroEOF
. If the argument has any other value, the behavior is undefined.
...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Note: XSI denotes an X/Open System Interfaces Extension to ISO/IEC 9945—POSIX. The functions are not defined by the C Standard.
...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <ctype.h> #include <stddef.h> ptrdiff_t count_preceding_whitespace(const char *s) { const char *t = s; /* possiblyPossibly *t < 0 */ while (*t && isspace(*t)) { ++t; } return t - s; } |
...
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
STR37-C | lowLow | unlikelyUnlikely | lowLow | P3 | L3 |
Automated Detection
Tool | Version | Checker | Description | ||||||
---|---|---|---|---|---|---|---|---|---|
Could detect violations of this rule by seeing if the argument to a character - handling function (listed above) is not an | |||||||||
| CC2.STR37 | Fully implemented | |||||||
PRQA QA-C |
| Special case of STR34-C | Fully implemented |
Related Vulnerabilities
...
CERT C Secure Coding Standard | STR34-C. Cast characters to unsigned char before converting to larger integer sizes |
CERT C++ Secure Coding Standard | STR37-CPP. Arguments to character handling functions must be representable as an unsigned char |
ISO/IEC TS 17961 (Draft) | Passing arguments to character-handling functions that are not representable as unsigned char [chrsgnext] |
MITRE CWE | CWE-704, Incorrect type conversion or cast CWE-686, Function call with incorrect argument type |
Bibliography
[ISO/IEC 9899:2011] | Subclause 7.4, "Character Handling <ctype.h >" |
[Kettlewell 2002] | Section 1.1, "<ctype.h > and Characters Types" |
...