Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

...

Compliant Solution (TR 24731-1)

Wiki MarkupThe {{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
bgColor#ccccff
langc
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

Section

LDRA tool suite

Include Page
c:LDRA_Vc:
LDRA_V
Section

115 S

Section

Fully Implemented

Section

Fortify SCA

Section

V. 5.0

 

Section

can detect violations of this rule with CERT C Rule Pack

Section

Compass/ROSE

 

 

Section

could detect violations in the following manner: All calls to strncpy() and the other functions should be follwed by an assignment of a terminating character to null-terminate the string

Section

Klocwork

Include Page
c:Klocwork_Vc:
Klocwork_V
Section

NNTS

 

Related Vulnerabilities

...

MITRE CWE: CWE-464, "Addition of Data Structure Sentinel"

Bibliography

Wiki Markup\[[Seacord 2005a|AA. Bibliography#Seacord 05a]\] Chapter 2, "Strings"

...

      07. Characters and Strings (STR)