Compartir a través de


PREfast Warning 59 (Windows CE 5.0)

Send Feedback

59 - Misuse of length parameter in call to <function>.
Recommended Fix: Pass the number of remaining characters, not the buffer size of <variable>.

This warning indicates that PREfast has detected a call to a string concatenation function that is probably passing an incorrect value for the number of characters to concatenate.

Although it might seem counterintuitive, functions such as strncat and wcsncat take the maximum number of parameters to concatenate, not the size of the buffer. This can result in an exploitable buffer overrun or crash.

A common cause of this defect is passing the buffer size, rather than the remaining number of characters in the buffer, to the string manipulation function.

Example

Defective Source

char arr[10];
arr[9] = 0;
strncpy(arr, arg1, 9);
strncat(arr, arg2, 10); // Wrong: this says to copy 10 chars.

Corrected Source

char arr[10];
arr[9] = 0;
strncpy(arr, arg1, 9);
strncat(arr, arg2, 9 - strlen(arr));

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.