...
This program does not typically raise an exception and may be exploited to overwrite memory at a specified location.
Compliant Solution
This compliant solution uses the {{ Wiki Markup basic_string
at()
}} method, which behaves in a similar fashion to the index {{operator
\[
\]
}} but throws an {{out_of_range
}} exception if {{pos
>=
size()
}}.
Code Block | ||||
---|---|---|---|---|
| ||||
string bs("01234567"); try { size_t i = f(); bs.at(i) = '\0'; } catch (...) { cerr << "Index out of range" << endl; } |
...
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
STR39-CPP | high | likely | high | P9 | L2 |
Bibliography
...
\[[Seacord 05|AA. Bibliography#Seacord 05]\] Chapter 2 Strings
\[
[ISO/IEC 14882-2003|AA. Bibliography#ISO/IEC 14882-2003] \] Section 21.3.4 basic_string element access
...
STR38-CPP. Use valid references, pointers, and iterators to reference string objects 07. Characters and Strings (STR) 08. Memory Management (MEM)