Skip to content

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

FieldValue
IDCODE-0811
CategoryGeneric
SeverityHIGH
CWECWE-369
ConfidenceHIGH
ImpactHIGH
LikelihoodMEDIUM
ExploitabilityEASY
Tagsdivision by zero, runtime error
OWASPN/A

References