Division by Zero
Description
The code is vulnerable to division by zero, which can cause a runtime error. The division operation is performed without checking if the divisor is zero.
Examples
Insecure Code
cairo
fn example() { let x = 5 / 0; }Secure Code
cairo
fn example() { let divisor = 5; if divisor != 0 { let x = 5 / divisor; } }Remediation
Add a check to ensure the divisor is not zero before performing the division.
Rule Details
| Field | Value |
|---|---|
| ID | CODE-0811 |
| Category | Generic |
| Severity | HIGH |
| CWE | CWE-369 |
| Confidence | HIGH |
| Impact | HIGH |
| Likelihood | MEDIUM |
| Exploitability | EASY |
| Tags | division by zero, runtime error |
| OWASP | N/A |