Securitylab•July 31, 2026•🇷🇺Translated from Russian

Dangerous C++ Traps: Memory Safety Issues, Undefined Behavior, and Code That Betrays Developers

Around 70% of vulnerabilities assigned CVE numbers by Microsoft each year are linked to memory safety errors. The Chromium project reported nearly identical statistics for serious Chrome bugs: roughly 70% arose from unsafe memory handling, with half of those defects involving use-after-free. Decades after widespread adoption of C and C++, the industry continues to encounter the same pitfalls, now embedded in browsers, servers, and firmware updates.

Undefined Behavior: When the Program Promises Nothing

Undefined behavior (UB) means the language imposes no requirements on program results once rules are violated. Compilers need not warn, processes need not crash, and output may be expected values, garbage, leaked secrets, or entirely different control flow after optimization. A classic example shows how an optimizer can assume signed overflow never occurs:

bool grows_after_increment(int value) {
    return value + 1 > value;
    // UB at INT_MAX allows optimizer to return true always
}

Use-After-Free: Address Exists, Object Does Not

Memory and objects are distinct in C++. Returning memory to the allocator while retaining a pointer creates use-after-free (CWE-416). std::unique_ptr reduces risk by expressing unique ownership, yet extracting a raw pointer via get() can still produce dangling references after the owner is destroyed.

Heartbleed: How a Separate Length Field Leaked Server Memory

In April 2014, Heartbleed (CVE-2014-0160) in OpenSSL demonstrated the cost of trusting a client-supplied length. The vulnerable heartbeat handler copied up to 64 KB without verifying the actual payload size, exposing session secrets, passwords, and private keys. The flaw was a read beyond bounds that often left the server running while silently leaking memory.

Buffer Overflows, Integer Overflows, and Dangling Views

Simple off-by-one errors using <= instead of < write past array ends. Integer overflow before allocation can produce a tiny buffer followed by a large memcpy. std::string_view and std::span store pointers and lengths without ownership; when the original string or vector is destroyed or reallocated, the view becomes dangling. C++20 and C++23 std::span lack an at() method; bounds-checked access arrived only in the technically complete C++26 via proposal P2821R5.

Data Races, Move Semantics, and Uninitialized Values

Concurrent unsynchronized writes to non-atomic objects produce data races classified as UB. After std::move, standard-library objects remain valid but hold unspecified values; relying on any particular state is a logic error. C++26 proposal P2795R5 introduces “erroneous behavior” for some reads of uninitialized automatic variables, giving compilers better diagnostic options without full UB freedom.

Dynamic Analysis Tools and Compiler Warnings

Recommended instrumented builds include:

  • AddressSanitizer (ASan) — detects out-of-bounds access and use-after-free (roughly 2× slowdown)
  • UndefinedBehaviorSanitizer (UBSan) — catches signed overflow and alignment issues
  • MemorySanitizer (MSan) — finds reads of uninitialized data
  • ThreadSanitizer (TSan) — identifies data races (5–15× slowdown)

Strict warning sets with -Wall -Wextra -Wpedantic -Wconversion -Wshadow plus -Wreturn-stack-address (Clang) or -fanalyzer (GCC) catch many issues at compile time. New projects should treat warnings as errors; legacy codebases benefit from freezing existing debt and enforcing clean modules for untrusted input.

Migration Advice and When to Choose Another Language

Teams should begin at trust boundaries: network packet handlers, file parsers, and decoders. Ownership should move to containers or std::unique_ptr following the rule of zero. For new services handling untrusted data without legacy constraints, memory-safe languages such as Rust eliminate entire classes of lifetime and ownership defects before compilation.

Related articles

Habr•Vulnerabilities & Exploits

Critical NFS2ROOT Vulnerability CVE-2026-99362 in Linux Kernel nfsd Allows Unauthenticated Remote Root Access

Researchers from OpenSec have disclosed NFS2ROOT (CVE-2026-99362), a critical vulnerability in the Linux kernel's NFS server module (nfsd) that enables remote code execution with kernel privileges without any authentication. The flaw affects systems running NFSv4.1 and NFSv4.2 and carries a CVSS score of 9.8. Exploitation requires only a single TCP connection to port 2049 and stems from a buffer overflow in the session slot caching mechanism of nfsd4_sequence(). A working exploit has been demonstrated that achieves kernel memory leaks, ASLR bypass, and arbitrary code execution via a crafted callback handler. The issue has existed since Linux 3.16 and is fixed in kernels 6.12.117, 6.18.61, 7.3.2, and 7.4-rc1. Administrators are advised to block external access to TCP port 2049 or disable the vulnerable protocol versions until patches are applied.

Habr•Vulnerabilities & Exploits

Anthropic Uses Claude to Discover Theoretical Attack on Post-Quantum Standards ML-KEM and ML-DSA

Anthropic has published research showing that its Claude models helped identify a new algorithm capable of solving the underlying lattice problems in ML-KEM and ML-DSA faster than previous methods on very large key sizes. The attack targets the Module-LWE problem and offers only asymptotic improvements that remain slower than existing techniques when applied to real-world parameter sets currently deployed by Amazon, Signal, and the NSA. Independent experts from the Cryptography Incident Review Group reviewed the findings and concluded that the method does not pose an immediate practical threat but represents an early warning signal for structured lattices. Scott Aaronson and Bart Preneel described the result as theoretically significant yet requiring further breakthroughs before any real-world impact on post-quantum cryptography becomes feasible. Anthropic recommends continuing migration to post-quantum standards using hybrid configurations that allow rapid algorithm replacement if future vulnerabilities emerge.

Habr•Vulnerabilities & Exploits

Anthropic Set to Publish Quantum Algorithm Breaking RingLWE and ModuleLWE Assumptions

Anthropic is preparing to release a paper titled 'Quasi-Polynomial Quantum Algorithms for Integral Lattices and Small-Rank Modular Lattices over Cyclotomic Rings That Are Powers of Two'. The work demonstrates a quasi-polynomial quantum algorithm capable of solving RingLWE and ModuleLWE problems that underpin several NIST post-quantum cryptography standards. Charles Hoskinson previously tweeted a cryptographic hash of the title to signal prior knowledge, while Michael DeBono later reconstructed the full title using Gemini and Fable. Scott Aaronson had already discussed related rumors in his blog, confirming he heard the claims but could not verify every detail. The attack requires a scalable quantum computer and currently features large constants that render it impractical, yet the result still forces reconsideration of structured lattice assumptions. NIST standards finalized in 2022 that rely on these problems now face renewed scrutiny, potentially pushing migration toward unstructured LWE variants with larger key sizes.

Security NEXT•Vulnerabilities & Exploits

Cacti Network Monitoring Tool Patched for SQL Injection Vulnerability Enabling OS Command Execution

The open-source network monitoring tool Cacti has been found vulnerable to an SQL injection flaw that allows attackers to manipulate database operations through crafted user settings. The vulnerability affects version 1.2.31 and earlier releases, enabling privilege escalation from standard user rights to administrator level and subsequent execution of operating system commands. A security advisory was published on November 29, 2026, identifying the issue as GHSA-5x85-g4vc-gq53 with a CVSS v3.1 base score of 8.8 rated High. Proof-of-concept code has been released publicly, and an exploitation technique named 4HTTP2SHELL was disclosed on November 26. Security firm Previdian observed SQL injection attempts against honeypots as early as November 27, confirming active exploitation in the wild. A fix is scheduled for the upcoming 1.2.32 release, while immediate mitigations include disabling guest access and restricting web interface exposure.