---
title: "CWE-561: Dead Code"
url: https://radicalnotion.ai/cwe/cwe-561
type: cwe
description: "The product contains dead code, which can never be executed."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-561: Dead Code

- **Abstraction:** Base
- **Structure:** Simple
- **Status:** Draft
- **CVEs with this as primary weakness:** 10
- **Of those, in CISA KEV:** 0
- **New in 2026:** 1
- **CWE catalog version:** 4.21

## Description

The product contains dead code, which can never be executed.

As originally described in CWE before CWE 5.0, "dead code is code that can never be executed in a running program. The surrounding code makes it impossible for a section of code to ever be executed." This term might be defined differently by some users.

## Modes of introduction

| Phase | Note |
| --- | --- |
| Implementation | - |

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Other | Quality Degradation | Dead code that results from code that can never be executed is an indication of problems with the source code that needs to be fixed and is an indication of poor quality. |
| Other | Reduce Maintainability | - |
| Other | Varies by Context, Execute Unauthorized Code or Commands | In some cases, dead code can be reachable or exploitable by attackers after they exploit another weakness or vulnerability that can access the code. For example, some buffer overflow exploits could modify addresses to point to locations that contain dead code. |

## Potential mitigations

### Implementation

Remove dead code before deploying the application.

## Detection methods

### Architecture or Design Review

According to SOAR \[REF-1479\], the following detection techniques may be useful:

Highly cost effective:

Cost effective for partial coverage:

- Inspection (IEEE 1028 standard) (can apply to requirements, design, source code, etc.)
- Formal Methods / Correct-By-Construction
- Attack Modeling

Effectiveness: High

### Automated Static Analysis - Binary or Bytecode

According to SOAR \[REF-1479\], the following detection techniques may be useful:

Highly cost effective:

- Binary / Bytecode Quality Analysis
- Compare binary / bytecode to application permission manifest

Effectiveness: High

### Dynamic Analysis with Manual Results Interpretation

According to SOAR \[REF-1479\], the following detection techniques may be useful:

Cost effective for partial coverage:

- Automated Monitored Execution

Effectiveness: SOAR Partial

### Automated Static Analysis

According to SOAR \[REF-1479\], the following detection techniques may be useful:

Cost effective for partial coverage:

- Permission Manifest Analysis

Effectiveness: SOAR Partial

### Automated Static Analysis - Source Code

According to SOAR \[REF-1479\], the following detection techniques may be useful:

Highly cost effective:

Cost effective for partial coverage:

- Source Code Quality Analyzer
- Warning Flags
- Source code Weakness Analyzer
- Context-configured Source Code Weakness Analyzer

Effectiveness: High

### Dynamic Analysis with Automated Results Interpretation

According to SOAR \[REF-1479\], the following detection techniques may be useful:

Cost effective for partial coverage:

- Web Application Scanner
- Web Services Scanner
- Database Scanners

Effectiveness: SOAR Partial

### Manual Static Analysis - Source Code

According to SOAR \[REF-1479\], the following detection techniques may be useful:

Highly cost effective:

Cost effective for partial coverage:

- Manual Source Code Review (not inspections)
- Focused Manual Spotcheck - Focused manual analysis of source

Effectiveness: High

## Demonstrative examples

### Example 1

The condition for the second if statement is impossible to satisfy. It requires that the variables be non-null. However, on the only path where s can be assigned a non-null value, there is a return statement.

Bad code:

```c++
String s = null;
if (b) {
    s = "Yes";
    return;
}

if (s != null) {
    Dead();
}
```

### Example 2

In the following class, two private methods call each other, but since neither one is ever invoked from anywhere else, they are both dead code.

Bad code:

```java
public class DoubleDead {
    private void doTweedledee() {
        doTweedledumb();
    }
    private void doTweedledumb() {
        doTweedledee();
    }
    public static void main(String[] args) {
        System.out.println("running DoubleDead");
    }
}
```

(In this case it is a good thing that the methods are dead: invoking either one would cause an infinite loop.)

### Example 3

The field named glue is not used in the following class. The author of the class has accidentally put quotes around the field name, transforming it into a string constant.

Bad code:

```java
public class Dead {
    String glue;

    public String getGlue() {
        return "glue";
    }
}
```

## Observed examples

| CVE | Description |
| --- | --- |
| CVE-2014-1266 | Chain: incorrect "goto" in Apple SSL product bypasses certificate validation, allowing Adversary-in-the-Middle (AITM) attack (Apple "goto fail" bug). CWE-705 (Incorrect Control Flow Scoping) -\> CWE-561 (Dead Code) -\> CWE-295 (Improper Certificate Validation) -\> CWE-393 (Return of Wrong Status Code) -\> CWE-300 (Channel Accessible by Non-Endpoint). The code's whitespace indentation did not reflect the actual control flow (CWE-1114) and did not explicitly delimit the block (CWE-483), which could have made it more difficult for human code auditors to detect the vulnerability. |

## Real CVEs with this weakness

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2025-34205 | Vasion Print (formerly PrinterLogic) Dangerous PHP Dead Code Enables RCE | critical | 9.3 | - | No | 2025-09-19 |
| CVE-2018-16543 | ghostscript: gssetresolution and gsgetresolution memory corruption (699670) | high | 7.8 | - | No | 2018-09-05 |
| CVE-2024-8300 | Malicious Code Execution Vulnerability in GENESIS64 and ICONICS Suite | high | 7.0 | - | No | 2024-11-28 |
| CVE-2023-52828 | bpf: Detect IP == ksym.end as part of BPF program | medium | 6.6 | - | No | 2024-05-21 |
| CVE-2024-32634 | Logically dead code | medium | 6.1 | - | No | 2024-04-16 |
| CVE-2022-33685 | - | medium | 5.5 | - | No | 2022-07-11 |
| CVE-2022-30748 | - | medium | 5.5 | - | No | 2022-06-07 |
| CVE-2022-33726 | - | low | 3.3 | - | No | 2022-08-05 |
| CVE-2021-25398 | - | low | 3.3 | - | No | 2021-06-11 |
| CVE-2026-44057 | Dead bounds check in Spotlight RPC unmarshaller | low | 3.1 | - | No | 2026-05-21 |

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-1164](https://radicalnotion.ai/cwe/cwe-1164) | Irrelevant Code |
| Child | [CWE-107](https://radicalnotion.ai/cwe/cwe-107) | Struts: Unused Validation Form |
| Related | [CWE-570](https://radicalnotion.ai/cwe/cwe-570) | Expression is Always False |
| Related | [CWE-571](https://radicalnotion.ai/cwe/cwe-571) | Expression is Always True |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| CERT C Secure Coding | Detect and remove dead code | MSC07-C | - |
| SEI CERT Perl Coding Standard | Detect and remove dead code | MSC00-PL | Exact |
| Software Fault Patterns | Unused Entities | SFP2 | - |
| OMG ASCMM | - | ASCMM-MNT-20 | - |

## Frequently asked questions

### What is CWE-561?

The product contains dead code, which can never be executed.

### What CVEs are caused by CWE-561?

10 recorded CVEs are attributed to CWE-561, including CVE-2025-34205, CVE-2018-16543 and CVE-2024-8300.

### How do you prevent CWE-561?

Remove dead code before deploying the application.

### How is CWE-561 detected?

Architecture or Design Review: According to SOAR, the following detection techniques may be useful:

### What are the consequences of CWE-561?

Exploiting CWE-561 can lead to: Quality Degradation, Reduce Maintainability, Varies by Context, Execute Unauthorized Code or Commands.

### Is CWE-561 actively exploited?

10 recorded CVEs are caused by CWE-561; none are currently in CISA's KEV catalog of actively exploited flaws.

Primary source: [MITRE CWE](https://cwe.mitre.org/data/definitions/561.html)

---

Source: [RadicalNotion.AI](https://radicalnotion.ai/cwe/cwe-561). Licensed CC BY-NC 4.0; attribute RadicalNotion.AI and link the source page when you reuse this data.
