CWE-395 使用NullPointerException捕捉来检测空指针解引用

admin 2021年12月16日16:01:25评论91 views字数 2169阅读7分13秒阅读模式

CWE-395 使用NullPointerException捕捉来检测空指针解引用

Use of NullPointerException Catch to Detect NULL Pointer Dereference

结构: Simple

Abstraction: Base

状态: Draft

被利用可能性: unkown

基本描述

Catching NullPointerException should not be used as an alternative to programmatic checks to prevent dereferencing a null pointer.

扩展描述

Programmers typically catch NullPointerException under three circumstances:

Of these three circumstances, only the last is acceptable.

相关缺陷

  • 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

适用平台

Language: {'cwe_Name': 'Java', 'cwe_Prevalence': 'Undetermined'}

常见的影响

范围 影响 注释
Availability DoS: Resource Consumption (CPU)

检测方法

Automated Static Analysis - Binary or Bytecode

According to SOAR, the following detection techniques may be useful:

Cost effective for partial coverage:
  • Bytecode Weakness Analysis - including disassembler + source code weakness analysis
  • Binary Weakness Analysis - including disassembler + source code weakness analysis

Dynamic Analysis with Manual Results Interpretation

According to SOAR, the following detection techniques may be useful:

Cost effective for partial coverage:
  • Framework-based Fuzzer

Manual Static Analysis - Source Code

According to SOAR, the following detection techniques may be useful:

Cost effective for partial coverage:
  • Manual Source Code Review (not inspections)

Automated Static Analysis - Source Code

According to SOAR, the following detection techniques may be useful:

Highly cost effective:
  • Source code Weakness Analyzer
  • Context-configured Source Code Weakness Analyzer

Architecture or Design Review

According to SOAR, the following detection techniques may be useful:

Highly cost effective:
  • Formal Methods / Correct-By-Construction
Cost effective for partial coverage:
  • Inspection (IEEE 1028 standard) (can apply to requirements, design, source code, etc.)

可能的缓解方案

['Architecture and Design', 'Implementation']

策略:

Do not extensively rely on catching exceptions (especially for validating user input) to handle errors. Handling exceptions can decrease the performance of an application.

示例代码

The following code mistakenly catches a NullPointerException.

bad Java

try {

mysteryMethod();

} catch (NullPointerException npe) {

}

分类映射

映射的分类名 ImNode ID Fit Mapped Node Name
7 Pernicious Kingdoms Catching NullPointerException
The CERT Oracle Secure Coding Standard for Java (2011) ERR08-J Do not catch NullPointerException or any of its ancestors

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

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2021年12月16日16:01:25
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   CWE-395 使用NullPointerException捕捉来检测空指针解引用http://cn-sec.com/archives/613149.html

发表评论

匿名网友 填写信息