CWE-135 多字节字符串长度的计算不正确

admin 2022年1月7日02:54:10评论42 views字数 2606阅读8分41秒阅读模式

CWE-135 多字节字符串长度的计算不正确

Incorrect Calculation of Multi-Byte String Length

结构: Simple

Abstraction: Base

状态: Draft

被利用可能性: unkown


The software does not correctly calculate the length of strings that can contain wide or multi-byte characters.


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


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


范围 影响 注释
['Integrity', 'Confidentiality', 'Availability'] Execute Unauthorized Code or Commands This weakness may lead to a buffer overflow. Buffer overflows often can be used to execute arbitrary code, which is usually outside the scope of a program's implicit security policy. This can often be used to subvert any other security service.
['Availability', 'Confidentiality'] ['Read Memory', 'DoS: Crash, Exit, or Restart', 'DoS: Resource Consumption (CPU)', 'DoS: Resource Consumption (Memory)'] Out of bounds memory access will very likely result in the corruption of relevant memory, and perhaps instructions, possibly leading to a crash. Other attacks leading to lack of availability are possible, including putting the program into an infinite loop.
Confidentiality Read Memory In the case of an out-of-bounds read, the attacker may have access to sensitive information. If the sensitive information contains system details, such as the current buffers position in memory, this knowledge can be used to craft further attacks, possibly with more severe consequences.



策略: Input Validation

Always verify the length of the string unit character.


策略: Libraries or Frameworks

Use length computing functions (e.g. strlen, wcslen, etc.) appropriately with their equivalent type (e.g.: byte, wchar_t, etc.)


The following example would be exploitable if any of the commented incorrect malloc calls were used.

bad C


int main() {

wchar_t wideString[] = L"The spazzy orange tiger jumped "
"over the tawny jaguar.";
wchar_t newString;

printf("Strlen() output: %dnWcslen() output: %dn",
strlen(wideString), wcslen(wideString));

/ Wrong because the number of chars in a string isn't related to its length in bytes //
newString = (wchar_t ) malloc(strlen(wideString));

/ Wrong because wide characters aren't 1 byte long! //
newString = (wchar_t
) malloc(wcslen(wideString));

/ Wrong because wcslen does not include the terminating null /
newString = (wchar_t
) malloc(wcslen(wideString) * sizeof(wchar_t));

/ correct! /
newString = (wchar_t ) malloc((wcslen(wideString) + 1) * sizeof(wchar_t));

/ ... */


The output from the printf() statement would be:


Strlen() output: 0
Wcslen() output: 53


映射的分类名 ImNode ID Fit Mapped Node Name
CLASP Improper string length checking
The CERT Oracle Secure Coding Standard for Java (2011) FIO10-J Ensure the array is filled when using read() to fill an array
Software Fault Patterns SFP10 Incorrect Buffer Length Computation



特别标注: 本站(CN-SEC.COM)所有文章仅供技术研究,若将其信息做其他用途,由用户承担全部法律及连带责任,本站不承担任何法律及连带责任,请遵守中华人民共和国安全法.
  • 我的微信
  • 微信扫一扫
  • weinxin
  • 我的微信公众号
  • 微信扫一扫
  • weinxin
  • 本文由 发表于 2022年1月7日02:54:10
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                  CWE-135 多字节字符串长度的计算不正确


匿名网友 填写信息

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