CWE-253 对函数返回值的检查不正确

Incorrect Check of Function Return Value

结构: Simple

Abstraction: Base

状态: Incomplete

被利用可能性: Low


The software incorrectly checks a return value from a function, which prevents the software from detecting errors or exceptional conditions.


Important and common functions will return some value about the success of its actions. This will alert the program whether or not to handle any errors caused by that function.


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

  • cwe_Nature: ChildOf cwe_CWE_ID: 754 cwe_View_ID: 1000


Language: {'cwe_Class': 'Language-Independent', 'cwe_Prevalence': 'Undetermined'}


范围 影响 注释
['Availability', 'Integrity'] ['Unexpected State', 'DoS: Crash, Exit, or Restart'] An unexpected return value could place the system in a state that could lead to a crash or other unintended behaviors.


Architecture and Design

策略: Language Selection

Use a language or compiler that uses exceptions and requires the catching of those exceptions.



Properly check all functions which return a value.



When designing any function make sure you return a value or throw an exception in case of an error.


This code attempts to allocate memory for 4 integers and checks if the allocation succeeds.

bad C

tmp = malloc(sizeof(int) * 4);
if (tmp < 0 ) {
//should have checked if the call returned 0

The code assumes that only a negative return value would indicate an error, but malloc() may return a null pointer when there is an error. The value of tmp could then be equal to 0, and the error would be missed.


映射的分类名 ImNode ID Fit Mapped Node Name
CLASP Misinterpreted function return value
Software Fault Patterns SFP4 Unchecked Status Condition
CERT C Secure Coding ERR33-C Imprecise Detect and handle standard library errors
CERT C Secure Coding POS54-C Imprecise Detect and handle POSIX library errors