---
title: "CWE-562: Return of Stack Variable Address"
url: https://radicalnotion.ai/cwe/cwe-562
type: cwe
description: "A function returns the address of a stack variable."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-562: Return of Stack Variable Address

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

## Description

A function returns the address of a stack variable.

Because local variables are allocated on the stack, when a program returns a pointer to a local variable, it is returning a stack address. A subsequent function call is likely to re-use this same stack address, thereby overwriting the value of the pointer, which no longer corresponds to the same variable since a function's stack frame is invalidated when it returns. At best this will cause the value of the pointer to change unexpectedly. In many cases it causes the program to crash the next time the pointer is dereferenced.

## Modes of introduction

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

## Applicable platforms

**Languages:** C (Undetermined), C++ (Undetermined)

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Availability, Integrity, Confidentiality | Read Memory, Modify Memory, Execute Unauthorized Code or Commands, DoS: Crash, Exit, or Restart | If the returned stack buffer address is dereferenced after the return, then an attacker may be able to modify or read memory, depending on how the address is used. If the address is used for reading, then the address itself may be exposed, or the contents that the address points to. If the address is used for writing, this can lead to a crash and possibly code execution. |

## Potential mitigations

### Implementation

Fix the code so that it does not return a stack address.

## Detection methods

### Fuzzing

Fuzz testing (fuzzing) is a powerful technique for generating large numbers of diverse inputs - either randomly or algorithmically - and dynamically invoking the code with those inputs. Even with random inputs, it is often capable of generating unexpected results such as crashes, memory corruption, or resource consumption. Fuzzing effectively produces repeatable test cases that clearly indicate bugs, which helps developers to diagnose the issues.

Effectiveness: High

### 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.)

Effectiveness: High

### Automated Dynamic Analysis

Use tools that are integrated during compilation to insert runtime error-checking mechanisms related to memory safety errors, such as AddressSanitizer (ASan) for C/C++ \[REF-1518\].

Effectiveness: Moderate. Crafted inputs are necessary to reach the code containing the error, such as generated by fuzzers. Also, these tools may reduce performance, and they only report the error condition - not the original mistake that led to the error.

## Demonstrative examples

### Example 1

The following function returns a stack address.

Bad code:

```c
char* getName() {
    char name[STR_MAX];
    fillInName(name);
    return name;
}
```

## Observed examples

| CVE | Description |
| --- | --- |
| CVE-2024-33045 | product returns stack variable address, leading to memory corruption |

## Real CVEs with this weakness

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2022-41837 | openimageio: out-of-bounds write vulnerability | critical | 9.8 | - | No | 2022-12-23 |
| CVE-2024-46823 | kunit/overflow: Fix UB in overflow\_allocation\_test | high | 8.4 | - | No | 2024-09-27 |
| CVE-2024-33045 | Return of Stack Variable Address in Buses | high | 8.4 | - | No | 2024-09-02 |
| CVE-2026-80975 | mfd: qnap-mcu: keep the reply buffer alive past a command timeout | high | 7.8 | - | No | 2026-09-11 |
| CVE-2021-21798 | Nitro Pro PDF JavaScript document.flattenPages JSStackFrame stack-based use-after-free vulnerability | high | 7.8 | - | No | 2021-09-15 |
| CVE-2024-4418 | Libvirt: stack use-after-free in virnetclientioeventloop() | medium | 6.2 | - | No | 2024-05-08 |
| CVE-2026-72433 | netfilter: nft\_meta\_bridge: fix NFT\_META\_BRI\_IIFPVID stack leak | medium | 5.5 | - | No | 2026-08-15 |
| CVE-2020-21686 | nasm: stack-use-after-scope in expand\_mmac\_params() in preproc.c | medium | 5.5 | - | No | 2023-08-22 |
| CVE-2026-3591 | A stack use-after-return flaw in SIG(0) handling code may enable ACL bypass | medium | 5.4 | - | No | 2026-03-25 |
| CVE-2026-26399 | - | medium | 5.3 | - | No | 2026-04-20 |
| CVE-2025-23155 | net: stmmac: Fix accessing freed irq affinity\_hint | medium | 4.8 | - | No | 2025-05-01 |
| CVE-2026-34553 | iccDEV: DoS in CIccCLUT::Iterate() & CIccMBB::Describe() | medium | 4.0 | - | No | 2026-03-31 |

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-758](https://radicalnotion.ai/cwe/cwe-758) | Reliance on Undefined, Unspecified, or Implementation-Defined Behavior |
| Can precede | [CWE-672](https://radicalnotion.ai/cwe/cwe-672) | Operation on a Resource after Expiration or Release |
| Can precede | [CWE-825](https://radicalnotion.ai/cwe/cwe-825) | Expired Pointer Dereference |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| CERT C Secure Coding | Declare objects with appropriate storage durations | DCL30-C | CWE More Specific |
| CERT C Secure Coding | Do not call putenv() with a pointer to an automatic variable as the argument | POS34-C | - |
| Software Fault Patterns | Glitch in computation | SFP1 | - |

## Frequently asked questions

### What is CWE-562?

A function returns the address of a stack variable.

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

12 recorded CVEs are attributed to CWE-562, including CVE-2022-41837, CVE-2024-46823 and CVE-2024-33045.

### How do you prevent CWE-562?

Fix the code so that it does not return a stack address.

### How is CWE-562 detected?

Fuzzing: Fuzz testing (fuzzing) is a powerful technique for generating large numbers of diverse inputs - either randomly or algorithmically - and dynamically invoking the code with those inputs. Even with random inputs, it is often capable of generating unexpected results such as crashes, memory corruption, or resource consumption. Fuzzing effectively produces repeatable test cases that clearly indicate bugs, which helps developers to diagnose the issues.

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

Exploiting CWE-562 can lead to: Read Memory, Modify Memory, Execute Unauthorized Code or Commands, DoS: Crash, Exit, or Restart.

### Is CWE-562 actively exploited?

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

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

---

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