CWE-14: Compiler Removal of Code to Clear Buffers
Sensitive memory is cleared according to the source code, but compiler optimizations leave the memory untouched when it is not read from again, aka "dead store removal."
How it's found
Compiler Removal of Code to Clear Buffers is a specific, narrowly defined instance of a broader pattern. Testers confirm it with targeted code review and a proof-of-concept input that exercises the exact code path this weakness describes.
This compiler optimization error occurs when:Secret data are stored in memory. The secret data are scrubbed from memory by overwriting its contents. The source code is compiled using an optimizing compiler, which identifies and removes the function that overwrites the contents as a dead store because the memory is not used subsequently.
Consequences
- Read Memory, Bypass Protection Mechanism: This weakness will allow data that has not been cleared from memory to be read. If this data contains sensitive password information, then an attacker can read the password and use the information to bypass protection mechanisms.
Mitigations
- Implementation: Store the sensitive data in a "volatile" memory location if available.
- Build and Compilation: If possible, configure your compiler so that it does not remove dead stores.
- Architecture and Design: Where possible, encrypt sensitive data that are used by a software system.
Where this fits in a TurboPentest engagement
This weakness is not covered by the automated black-box pentest. IntegSec pentesters cover it in a manual engagement.
Frequently asked questions
What is CWE-14?
Sensitive memory is cleared according to the source code, but compiler optimizations leave the memory untouched when it is not read from again, aka "dead store removal."
How do you find Compiler Removal of Code to Clear Buffers?
Compiler Removal of Code to Clear Buffers is a specific, narrowly defined instance of a broader pattern. Testers confirm it with targeted code review and a proof-of-concept input that exercises the exact code path this weakness describes.
What is the impact of CWE-14?
Read Memory, Bypass Protection Mechanism: This weakness will allow data that has not been cleared from memory to be read. If this data contains sensitive password information, then an attacker can read the password and use the information to bypass protection mechanisms.
Does TurboPentest test for Compiler Removal of Code to Clear Buffers?
This weakness is not covered by the automated black-box pentest. IntegSec pentesters cover it in a manual engagement.
Related CWEs
- Base weaknessCWE-733: Compiler Optimization Removal or Modification of Security-critical Code
- Base weaknessCWE-261: Weak Encoding for Password
- Class weaknessCWE-311: Missing Encryption of Sensitive Data
- Variant weaknessCWE-321: Use of Hard-coded Cryptographic Key
- Class weaknessCWE-326: Inadequate Encryption Strength
- Class weaknessCWE-327: Use of a Broken or Risky Cryptographic Algorithm
Written and reviewed by
Michel Chamberland - Founder & CEO, IntegSec
CISSP, OSCP, OSCE, CEH, GIAC, CCSK · 20+ years in offensive security
Michel has spent 20+ years on offensive security teams including IBM X-Force Red and Trustwave SpiderLabs, leading penetration tests, red team engagements, and breach response for Fortune 500 customers. He is the founder of IntegSec and the architect of TurboPentest.
Find these issues before an attacker does
TurboPentest runs an agentic AI pentest against your target and reports findings with proof, from $99 per target.
Start a pentest