CWE-396 对通用异常声明Catch语句

admin 2022年1月5日20:59:03CWE(弱点枚举)评论11 views2148字阅读7分9秒阅读模式

CWE-396 对通用异常声明Catch语句

Declaration of Catch for Generic Exception

结构: Simple

Abstraction: Base

状态: Draft

被利用可能性: unkown

基本描述

Catching overly broad exceptions promotes complex error handling code that is more likely to contain security vulnerabilities.

扩展描述

Multiple catch blocks can get ugly and repetitive, but "condensing" catch blocks by catching a high-level class like Exception can obscure exceptions that deserve special treatment or that should not be caught at this point in the program. Catching an overly broad exception essentially defeats the purpose of Java's typed exceptions, and can become particularly dangerous if the program grows and begins to throw new types of exceptions. The new exception types will not receive any attention.

相关缺陷

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

  • cwe_Nature: ChildOf cwe_CWE_ID: 755 cwe_View_ID: 1000

  • cwe_Nature: ChildOf cwe_CWE_ID: 221 cwe_View_ID: 1000

适用平台

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

常见的影响

范围 影响 注释
['Non-Repudiation', 'Other'] ['Hide Activities', 'Alter Execution Logic']

示例代码

The following code excerpt handles three types of exceptions in an identical fashion.

good Java

try {

doExchange();

}
catch (IOException e) {

logger.error("doExchange failed", e);

}
catch (InvocationTargetException e) {


logger.error("doExchange failed", e);

}
catch (SQLException e) {


logger.error("doExchange failed", e);

}

At first blush, it may seem preferable to deal with these exceptions in a single catch block, as follows:

bad

try {

doExchange();

}
catch (Exception e) {

logger.error("doExchange failed", e);

}

However, if doExchange() is modified to throw a new type of exception that should be handled in some different kind of way, the broad catch block will prevent the compiler from pointing out the situation. Further, the new catch block will now also handle exceptions derived from RuntimeException such as ClassCastException, and NullPointerException, which is not the programmer's intent.

分类映射

映射的分类名 ImNode ID Fit Mapped Node Name
7 Pernicious Kingdoms Overly-Broad Catch Block
Software Fault Patterns SFP5 Ambiguous Exception Type
OMG ASCSM ASCSM-CWE-396
OMG ASCRM ASCRM-CWE-396

引用

文章来源于互联网:scap中文网

特别标注: 本站(CN-SEC.COM)所有文章仅供技术研究,若将其信息做其他用途,由用户承担全部法律及连带责任,本站不承担任何法律及连带责任,请遵守中华人民共和国安全法.
  • 我的微信
  • 微信扫一扫
  • weinxin
  • 我的微信公众号
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2022年1月5日20:59:03
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                  CWE-396 对通用异常声明Catch语句 http://cn-sec.com/archives/612869.html

发表评论

匿名网友 填写信息

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