You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>Potentially dangerous use of the strlen function to calculate the length of a string.
7
+
The expression <code>buffer[strlen(buffer)] = 0</code> is potentially dangerous, if the variable buffer does not have a terminal zero, then access beyond the bounds of the allocated memory is possible, which will lead to undefined behavior.
8
+
If terminal zero is present, then the specified expression is meaningless.</p>
9
+
10
+
<p>False positives include heavily nested strlen. This situation is unlikely.</p>
11
+
12
+
</overview>
13
+
<recommendation>
14
+
15
+
<p>We recommend using another method for calculating the string length</p>
16
+
17
+
</recommendation>
18
+
<example>
19
+
<p>The following example demonstrates an erroneous and corrected use of the strlen function.</p>
<ahref="https://wiki.sei.cmu.edu/confluence/display/c/STR32-C.+Do+not+pass+a+non-null-terminated+character+sequence+to+a+library+function+that+expects+a+string">STR32-C. Do not pass a non-null-terminated character sequence to a library function that expects a string</a>.
* @name Access Of Memory Location After End Of Buffer
3
+
* @description The expression `buffer [strlen (buffer)] = 0` is potentially dangerous, if the variable `buffer` does not have a terminal zero, then access beyond the bounds of the allocated memory is possible, which will lead to undefined behavior.
4
+
* If terminal zero is present, then the specified expression is meaningless.
0 commit comments