20
References
[REF-960]Object Management Group (OMG). "Automated Source Code Maintainability Measure
(ASCMM)". 2016 January. < https://www.omg.org/spec/ASCMM/ >.2023-04-07.
CWE-562: Return of Stack Variable Address
Weakness ID : 562
Structure : Simple
Abstraction : Base
Description
A function returns the address of a stack variable, which will cause unintended program behavior,
typically in the form of a crash.
Extended Description
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.
Relationships
The table(s) below shows the weaknesses and high level categories that are related to this
weakness. These relationships are defined as ChildOf, ParentOf, MemberOr and give insight to
similar items that may exist at higher and lower levels of abstraction. In addition, relationships such
as PeerOf and CanAlsoBe are defined to show similar weaknesses that may want to be explored.
Relevant to the view "Research Concepts" (CWE-1000)
Nature Type ID Name Page
ChildOf 758 Reliance on Undefined, Unspecified, or Implementation-
Defined Behavior