CWE Database
/

CWE-562

Back to CWE list

CWE-562

Return of Stack Variable Address

Base
Draft

Description

A function returns the address of a stack variable, which will cause unintended program behavior, typically in the form of a crash.

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.

Common Consequences

Scope

Availability
Integrity
Confidentiality

Impact

Read Memory, Modify Memory, Execute Unauthorized Code or Commands, DoS: Crash, Exit, or Restart

Potential Mitigations

Implementation

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

CVE-2024-33045

product returns stack variable address, leading to memory corruption

Applicable Platforms

C
C++

Security Training

Train your team to recognize and prevent security threats with our comprehensive security awareness program.

Start Training

Vulnerability Scanning

Discover vulnerabilities in your applications and infrastructure before attackers do.

Scan Now