原文地址:
https://cwe.mitre.org/data/definitions/787.html
1. 什么是 out-of-bound write
Description Summary
Extended Description
This typically occurs when the pointer or its index is incremented or decremented to a position beyond the bounds of the buffer or when pointer arithmetic results in a position outside of the valid memory location to name a few. This may result in corruption of sensitive information, a crash, or code execution among other things.
Example 1
The following code attempts to save four different identification numbers into an array.
Example 2
In the following example, it is possible to request that memcpy move a much larger segment of memory than assumed:
If returnChunkSize() happens to encounter an error it will return -1. Notice that the return value is not checked before the memcpy operation (CWE-252), so -1 can be passed as the size argument to memcpy() (CWE-805). Because memcpy() assumes that the value is unsigned, it will be interpreted as MAXINT-1 (CWE-195), and therefore will copy far more memory than is likely available to the destination buffer (CWE-787, CWE-788).
重点: returnChunkSize() 需要被check
CWE-787,也称为Out-of-bounds Write,是编程中的一种常见错误,可能导致敏感信息破坏、程序崩溃或代码执行。文章通过两个示例解释了这种错误的发生情况,强调了在使用指针或数组时未检查边界可能导致的问题。特别是在示例2中,由于未检查returnChunkSize()的返回值,memcpy可能会复制远超预期大小的内存块,从而引发严重后果。
5197

被折叠的 条评论
为什么被折叠?



