CWE-562
Weakness AllowedReturn of Stack Variable Address
Abstraction: Variant · Status: Draft
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.
Mapping guidance
This CWE entry is at the Base level of abstraction, which is a preferred level of abstraction for mapping to the root causes of vulnerabilities.
Carefully read both the name and description to ensure that this mapping is an appropriate fit. Do not try to 'force' a mapping to a lower-level Base/Variant simply to comply with this preferred level of abstraction.
Relationships and members
Modes of introduction
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.
Content history
updated Potential_Mitigations, Time_of_Introduction
updated Applicable_Platforms, Relationships, Other_Notes, Taxonomy_Mappings
updated Relationships, Taxonomy_Mappings
updated Demonstrative_Examples
updated Relationships
updated Common_Consequences
updated Relationships
updated Potential_Mitigations
updated Description, Other_Notes
updated Relationships, Taxonomy_Mappings
updated Relationships, Taxonomy_Mappings
updated Relationships, Weakness_Ordinalities
updated Relationships
updated Common_Consequences
updated Relationships
updated Relationships
updated Detection_Factors, Relationships
updated Mapping_Notes
updated Demonstrative_Examples
updated Affected_Resources, Functional_Areas
updated Detection_Factors, Observed_Examples, References
updated Potential_Mitigations
updated Description, References, Type
13 vulnerabilities reference this CWE, most recent first.
GHSA-MFMC-FMC9-6PH8
Vulnerability from github – Published: 2024-09-02 12:30 – Updated: 2024-09-02 12:30Memory corruption when BTFM client sends new messages over Slimbus to ADSP.
{
"affected": [],
"aliases": [
"CVE-2024-33045"
],
"database_specific": {
"cwe_ids": [
"CWE-562",
"CWE-787"
],
"github_reviewed": false,
"github_reviewed_at": null,
"nvd_published_at": "2024-09-02T12:15:16Z",
"severity": "HIGH"
},
"details": "Memory corruption when BTFM client sends new messages over Slimbus to ADSP.",
"id": "GHSA-mfmc-fmc9-6ph8",
"modified": "2024-09-02T12:30:45Z",
"published": "2024-09-02T12:30:45Z",
"references": [
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2024-33045"
},
{
"type": "WEB",
"url": "https://docs.qualcomm.com/product/publicresources/securitybulletin/september-2024-bulletin.html"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H",
"type": "CVSS_V3"
}
]
}
GHSA-Q262-3HFR-F5Q4
Vulnerability from github – Published: 2024-05-08 03:30 – Updated: 2025-04-12 00:30A race condition leading to a stack use-after-free flaw was found in libvirt. Due to a bad assumption in the virNetClientIOEventLoop() method, the data pointer to a stack-allocated virNetClientIOEventData structure ended up being used in the virNetClientIOEventFD callback while the data pointer's stack frame was concurrently being "freed" when returning from virNetClientIOEventLoop(). The 'virtproxyd' daemon can be used to trigger requests. If libvirt is configured with fine-grained access control, this issue, in theory, allows a user to escape their otherwise limited access. This flaw allows a local, unprivileged user to access virtproxyd without authenticating. Remote users would need to authenticate before they could access it.
{
"affected": [],
"aliases": [
"CVE-2024-4418"
],
"database_specific": {
"cwe_ids": [
"CWE-416",
"CWE-562"
],
"github_reviewed": false,
"github_reviewed_at": null,
"nvd_published_at": "2024-05-08T03:15:07Z",
"severity": "MODERATE"
},
"details": "A race condition leading to a stack use-after-free flaw was found in libvirt. Due to a bad assumption in the virNetClientIOEventLoop() method, the `data` pointer to a stack-allocated virNetClientIOEventData structure ended up being used in the virNetClientIOEventFD callback while the data pointer\u0027s stack frame was concurrently being \"freed\" when returning from virNetClientIOEventLoop(). The \u0027virtproxyd\u0027 daemon can be used to trigger requests. If libvirt is configured with fine-grained access control, this issue, in theory, allows a user to escape their otherwise limited access. This flaw allows a local, unprivileged user to access virtproxyd without authenticating. Remote users would need to authenticate before they could access it.",
"id": "GHSA-q262-3hfr-f5q4",
"modified": "2025-04-12T00:30:26Z",
"published": "2024-05-08T03:30:37Z",
"references": [
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2024-4418"
},
{
"type": "WEB",
"url": "https://access.redhat.com/errata/RHSA-2024:4351"
},
{
"type": "WEB",
"url": "https://access.redhat.com/errata/RHSA-2024:4432"
},
{
"type": "WEB",
"url": "https://access.redhat.com/errata/RHSA-2024:4757"
},
{
"type": "WEB",
"url": "https://access.redhat.com/security/cve/CVE-2024-4418"
},
{
"type": "WEB",
"url": "https://bugzilla.redhat.com/show_bug.cgi?id=2278616"
},
{
"type": "WEB",
"url": "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/4IE44UIIC3QWBFRB4EUSFNLJBU6JLNSD"
},
{
"type": "WEB",
"url": "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/Q4ZQBAJVHIZMCZNTRPUW3ZKXRKLXRQZU"
},
{
"type": "WEB",
"url": "https://security.netapp.com/advisory/ntap-20250411-0002"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H",
"type": "CVSS_V3"
}
]
}
GHSA-VXCH-4R45-JHW9
Vulnerability from github – Published: 2026-04-20 18:31 – Updated: 2026-04-21 21:31A stack-use-after-return issue exists in the Arduino_Core_STM32 library prior to version 1.7.0. The pwm_start() function allocates a TIM_HandleTypeDef structure on the stack and passes its address to HAL initialization routines, where it is stored in a global timer handle registry. After the function returns, interrupt service routines may dereference this dangling pointer, resulting in memory corruption.
{
"affected": [],
"aliases": [
"CVE-2026-26399"
],
"database_specific": {
"cwe_ids": [
"CWE-562",
"CWE-825"
],
"github_reviewed": false,
"github_reviewed_at": null,
"nvd_published_at": "2026-04-20T18:16:25Z",
"severity": "MODERATE"
},
"details": "A stack-use-after-return issue exists in the Arduino_Core_STM32 library prior to version 1.7.0. The pwm_start() function allocates a TIM_HandleTypeDef structure on the stack and passes its address to HAL initialization routines, where it is stored in a global timer handle registry. After the function returns, interrupt service routines may dereference this dangling pointer, resulting in memory corruption.",
"id": "GHSA-vxch-4r45-jhw9",
"modified": "2026-04-21T21:31:20Z",
"published": "2026-04-20T18:31:49Z",
"references": [
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2026-26399"
},
{
"type": "WEB",
"url": "https://github.com/Acen28/CVE-2026-26399-Disclosure"
},
{
"type": "WEB",
"url": "https://github.com/stm32duino/Arduino_Core_STM32/releases/tag/1.6.1"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:L/I:L/A:L",
"type": "CVSS_V3"
}
]
}
Mitigation
Fix the code so that it does not return a stack address.
No CAPEC attack patterns related to this CWE.