CWE-124 缓冲区下溢

admin 2022年1月2日04:15:11CWE(弱点枚举)评论22 views2561字阅读8分32秒阅读模式

CWE-124 缓冲区下溢

Buffer Underwrite ('Buffer Underflow')

结构: Simple

Abstraction: Base

状态: Incomplete

被利用可能性: Medium


The software writes to a buffer using an index or pointer that references a memory location prior to the beginning of the buffer.


This typically occurs when a pointer or its index is decremented to a position before the buffer, when pointer arithmetic results in a position before the beginning of the valid memory location, or when a negative index is used.


  • cwe_Nature: ChildOf cwe_CWE_ID: 786 cwe_View_ID: 1000 cwe_Ordinal: Primary

  • cwe_Nature: ChildOf cwe_CWE_ID: 786 cwe_View_ID: 699 cwe_Ordinal: Primary

  • cwe_Nature: ChildOf cwe_CWE_ID: 787 cwe_View_ID: 1000

  • cwe_Nature: ChildOf cwe_CWE_ID: 787 cwe_View_ID: 699


Language: [{'cwe_Name': 'C', 'cwe_Prevalence': 'Undetermined'}, {'cwe_Name': 'C++', 'cwe_Prevalence': 'Undetermined'}]


范围 影响 注释
['Integrity', 'Availability'] ['Modify Memory', 'DoS: Crash, Exit, or Restart'] Out of bounds memory access will very likely result in the corruption of relevant memory, and perhaps instructions, possibly leading to a crash.
['Integrity', 'Confidentiality', 'Availability', 'Access Control', 'Other'] ['Execute Unauthorized Code or Commands', 'Modify Memory', 'Bypass Protection Mechanism', 'Other'] If the corrupted memory can be effectively controlled, it may be possible to execute arbitrary code. If the corrupted memory is data rather than instructions, the system will continue to function with improper changes, possibly in violation of an implicit or explicit policy. The consequences would only be limited by how the affected data is used, such as an adjacent memory location that is used to specify whether the user has special privileges.
['Access Control', 'Other'] ['Bypass Protection Mechanism', 'Other'] When the consequence is arbitrary code execution, this can often be used to subvert any other security service.



Requirements specification: The choice could be made to use a language that is not susceptible to these issues.



Sanity checks should be performed on all calculated values used as index or for pointer arithmetic.


In the following C/C++ example, a utility function is used to trim trailing whitespace from a character string. The function copies the input string to a local character string and uses a while statement to remove the trailing whitespace by moving backward through the string and overwriting whitespace with a NUL character.

bad C

char trimTrailingWhitespace(char strMessage, int length) {

char retMessage;
message = malloc(sizeof(char)*(length+1));

// copy input string to a temporary string

char message[length+1];
int index;
for (index = 0; index message[index] = strMessage[index];

message[index] = '';

// trim trailing whitespace

int len = index-1;
while (isspace(message[len])) {

message[len] = '';


// return string without trailing whitespace

retMessage = message;
return retMessage;


特别标注: 本站(CN-SEC.COM)所有文章仅供技术研究,若将其信息做其他用途,由用户承担全部法律及连带责任,本站不承担任何法律及连带责任,请遵守中华人民共和国安全法.
  • 我的微信
  • 微信扫一扫
  • weinxin
  • 我的微信公众号
  • 微信扫一扫
  • weinxin
  • 本文由 发表于 2022年1月2日04:15:11
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                  CWE-124 缓冲区下溢


匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: