Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

According to Section 7.4 of C99 (see also undefined behavior 107 of Appendix J):

The header <ctype.h> declares several functions useful for classifying and mapping characters. In all cases the argument is an int, the value of which shall be representable as an unsigned char or shall equal the value of the macro EOF. If the argument has any other value, the behavior is undefined.

(See also undefined behavior 107 of Appendix J.)

Compliance with this rule is complicated by the fact that the char data type might, in any implementation, be signed or unsigned.

...

A generalization of this rule is guideline STR34-C. Cast characters to unsigned types before converting to larger integer sizes.

...

Rule

Severity

Likelihood

Remediation Cost

Priority

Level

STR37-C

low

unlikely

low

P3

L3

Automated Detection

Tool

Version

Checker

Description

Section

Compass/ROSE

 

 

Section

could detect violations of this rule by seeing if the argument to a character-handling function (listed above) is not an unsigned char

...

Related Vulnerabilities

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

Other Languages

Related Guidelines

This rule appears in the C++ Secure Coding Standard as : STR37-CPP. Arguments to character handling functions must be representable as an unsigned char.

Bibliography

Wiki Markup
\[[ISO/IEC 9899:1999|AA. Bibliography#ISO/IEC 9899-1999]\] Section 7.4, "Character handling <{{ctype.h}}>"
\[[Kettlewell 022002|AA. Bibliography#Kettle 02]\] Section 1.1, "<{{ctype.h}}> And Characters Types"
\[[MITRE 072007|AA. Bibliography#MITRE 07]\] [CWE ID 704|http://cwe.mitre.org/data/definitions/704.html], "Incorrect Type Conversion or Cast," [CWE ID 686|http://cwe.mitre.org/data/definitions/686.html], "Function Call With Incorrect Argument Type"

...