Movatterモバイル変換


[0]ホーム

URL:


CodeQL documentation
CodeQL resources

Unbounded write

ID: cpp/unbounded-writeKind: path-problemSecurity severity: 9.3Severity: errorPrecision: mediumTags:   - reliability   - security   - external/cwe/cwe-120   - external/cwe/cwe-787   - external/cwe/cwe-805Query suites:   - cpp-security-extended.qls   - cpp-security-and-quality.qls

Click to see the query in the CodeQL repository

The program performs a buffer copy or write operation with no upper limit on the size of the copy. An unexpectedly long input that reaches this code will cause the buffer to overflow. In addition to causing program instability, techniques exist which may allow an attacker to use this vulnerability to execute arbitrary code.

Recommendation

Always control the length of buffer copy and buffer write operations.strncpy should be used overstrcpy,snprintf oversprintf, and in other cases ‘n-variant’ functions should be preferred.

Example

voidcongratulateUser(constchar*userName){charbuffer[80];// BAD: this could overflow the buffer if the UserName is longsprintf(buffer,"Congratulations, %s!",userName);MessageBox(hWnd,buffer,"New Message",MB_OK);}

In this example, the call tosprintf may overflowbuffer. This occurs if the argumentuserName is very long, such that the resulting string is more than the 80 characters allowed.

To fix the problem the call tosprintf should be replaced withsnprintf, specifying a maximum length of 80 characters.

References


[8]ページ先頭

©2009-2025 Movatter.jp