Strings are a fundamental concept in software engineering, but they are not a built-in type in C. Null-terminated byte strings (NTBS) consist of a contiguous sequence of characters terminated by and including the first null NULL character. The C programming language supports the following types of nullNULL-terminated byte strings: single byte character strings, multibyte character strings, and wide character strings. Single byte and multibyte character strings are both described as nullNULL-terminated byte strings.
A pointer to a single byte or multibyte character string points to its initial character. The length of the string is the number of bytes preceding the null NULL character, and the value of the string is the sequence of the values of the contained characters, in order.
A wide string is a contiguous sequence of wide characters terminated by and including the first null NULL wide character. A pointer to a wide string points to its initial (lowest addressed) wide character. The length of a wide string is the number of wide characters preceding the null NULL wide character, and the value of a wide string is the sequence of code values of the contained wide characters, in order.
Null-terminated byte strings are implemented as arrays of characters and are susceptible to the same problems as arrays. As a result, rules and recommendations for arrays should also be applied to nullNULL-terminated byte strings.
...
STR03-A. Do not inadvertently truncate a null NULL terminated byte string
STR05-A. Prefer making string literals const-qualified
...
STR32-C. Null-terminate byte strings as required
...
Recommendation | Severity | Likelihood | Remediation Cost | Priority | Level |
|---|---|---|---|---|---|
STR00-A | 3 (high) | 2 (probable) | 2 (medium) | P12 | L1 |
STR01-A | 3 (high) | 2 (probable) | 1 (high) | P6 | L2 |
STR02-A | 2 (medium) | 3 (likely) | 2 (medium) | P12 | L1 |
STR03-A | 1 (low) | 1 (unlikely) | 2 (medium) | P2 | L3 |
STR05-A | 1 (low) | 3 (likely) | 2 (medium) | P6 | L3 L2 |
STR06-A | 2 (lowmedium) | 2 (probable) | 3 (low) | P12 | L1 |
STR07-A | 2 (medium) | 2 (probable) | 2 (medium) | P8 | L2 |
STR08-A | 1 (low) | 1 (unlikely) | 2 (medium) | P2 | L3 |
...