# Cwe 369 Divide By Zero

> Use this skill when you need to remediate CWE-369 (Divide By Zero) vulnerabilities in Java code. Triggers on SAST findings, security reviews, or when fixing divide by zero issues.

- Skill: `developerscoffee/cwe-369-divide-by-zero` (Agent Skill)
- Install (CLI): `npx skillmds@latest add developerscoffee/cwe-369-divide-by-zero`
- Raw SKILL.md: https://api.skillmd.com/api/skills/developerscoffee/cwe-369-divide-by-zero/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Security
- License: MIT
- Author: DevelopersCoffee (https://skillmd.com/u/developerscoffee)
- Updated: 2026-09-10
- Page: https://skillmd.com/skills/developerscoffee/cwe-369-divide-by-zero

---


# CWE-369 Divide By Zero

## Description

Divide By Zero

Reference:
https://cwe.mitre.org/data/definitions/369.html


**OWASP Category**: A03:2021 – Injection


---

## Vulnerable Pattern


### ❌ Example 1: Vulnerable Pattern

```java
// VULNERABLE: No check for zero divisor
int result = total / count;
```


**Why it's vulnerable:** This pattern is vulnerable to Divide By Zero




---

## Deterministic Fix


### ✅ Secure Implementation: Secure Implementation

```java
// SECURE: Check divisor before division
if (count == 0) {
    throw new IllegalArgumentException("Division by zero");
    // Or return default value
    // return 0;
}
int result = total / count;
```


**Why it's secure:** Implements proper protection against Divide By Zero




---

## Detection Pattern

Look for these patterns in your codebase:


```bash
# Find division operations
grep -rn "/[^/*]\\|% " --include="*.java" | grep -v "//"
```



---

## Remediation Steps


1. Always check divisor is not zero before division

2. Handle zero case explicitly with default value or exception


---

## Key Imports

```java

```

---

## Verification

After remediation:


- Run SAST scanner to confirm vulnerability is resolved

- Review all instances of the vulnerable pattern

- Add unit tests that verify the secure implementation

- Check for similar patterns in related code


---

## Trigger Examples

```
Fix CWE-369 vulnerability
Resolve Divide By Zero issue
Secure this Java code against divide by zero
SAST reports CWE-369
```

---

## Common Vulnerable Locations

| Layer | Files | Patterns |
|-------|-------|----------|

| Controller | `*Controller.java` | User input handling |

| Service | `*Service.java` | Business logic |

| Repository | `*Repository.java` | Data access |


---

## References


- [CWE-369: Divide By Zero](https://cwe.mitre.org/data/definitions/369.html)


---

**Source**: Generated by [Java CWE Security Skills Generator](https://github.com/DevelopersCoffee/java-cwe-security-skills)
**Last Updated**: 2026-03-07

