CWE-192: Integer Coercion Error
CWE版本: 4.18
更新日期: 2025-09-09
弱点描述
Integer coercion refers to a set of flaws pertaining to the type casting, extension, or truncation of primitive data types.
扩展描述
Several flaws fall under the category of integer coercion errors. For the most part, these errors in and of themselves result only in availability and data integrity issues. However, in some circumstances, they may result in other, more complicated security related flaws, such as buffer overflow conditions.
常见后果
影响范围: Availability
技术影响: DoS: Resource Consumption (CPU) DoS: Resource Consumption (Memory) DoS: Crash, Exit, or Restart
说明: Integer coercion often leads to undefined states of execution resulting in infinite loops or crashes.
影响范围: Integrity Confidentiality Availability
技术影响: Execute Unauthorized Code or Commands
说明: In some cases, integer coercion errors can lead to exploitable buffer overflow conditions, resulting in the execution of arbitrary code.
影响范围: Integrity Other
技术影响: Other
说明: Integer coercion errors result in an incorrect value being stored for the variable in question.
潜在缓解措施
阶段: Requirements
描述: A language which throws exceptions on ambiguous data casts might be chosen.
阶段: Architecture and Design
描述: Design objects and program flow such that multiple or complex casts are unnecessary
阶段: Implementation
描述: Ensure that any data type casting that you must used is entirely understood in order to reduce the plausibility of error in use.
检测方法
方法: Automated Static Analysis
Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)
有效性: High
观察示例
参考: CVE-2022-2639
Chain: integer coercion error (CWE-192) prevents a return value from indicating an error, leading to out-of-bounds write (CWE-787)
引入模式
| 阶段 | 说明 |
|---|---|
| Implementation | - |
适用平台
编程语言
分类映射
| 分类名称 | 条目ID | 条目名称 | 映射适配度 |
|---|---|---|---|
| CLASP | - | Integer coercion error | - |
| CERT C Secure Coding | INT02-C | Understand integer conversion rules | - |
| CERT C Secure Coding | INT05-C | Do not use input functions to convert character data if they cannot handle all possible inputs | - |
| CERT C Secure Coding | INT31-C | Ensure that integer conversions do not result in lost or misinterpreted data | Exact |