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

admin 2022年1月5日20:59:03评论72 views字数 2148阅读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中文网

免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2022年1月5日20:59:03
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   CWE-396 对通用异常声明Catch语句http://cn-sec.com/archives/612869.html
                  免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉.

发表评论

匿名网友 填写信息