...
Compliant Solution (TR 24731-1)
The {{Wiki Markup strcpy_s()}} function defined in \[ [ISO/IEC TR 24731-1:2007|AA. Bibliography#ISO/IEC TR 24731-1-2007]\] provides additional safeguards, including accepting the size of the destination buffer as an additional argument. (See recommendation [STR07-C. Use the bounds-checking interfaces for remediation of existing string manipulation code].) Also {{strnlen_s()}} accepts a maximum-length argument for strings that may not be null-terminated.
| Code Block | ||||
|---|---|---|---|---|
| ||||
char *string_data = NULL;
char a[16];
/* ... */
if (string_data == NULL) {
/* Handle null pointer error */
}
else if (strnlen_s(string_data, sizeof(a)) >= sizeof(a)) {
/* Handle overlong string error */
}
else {
strcpy_s(a, sizeof(a), string_data);
}
|
...
Recommendation | Severity | Likelihood | Remediation Cost | Priority | Level |
|---|---|---|---|---|---|
STR03-C | medium | probable | medium | P8 | L2 |
Automated Detection
Tool | Version | Checker | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
|
| ||||||||||||
|
|
|
| ||||||||||||
|
|
|
| ||||||||||||
|
|
|
|
Related Vulnerabilities
...
MITRE CWE: CWE-464, "Addition of Data Structure Sentinel"
Bibliography
\[[Seacord 2005a|AA. Bibliography#Seacord 05a]\] Chapter 2, "Strings"Wiki Markup
...