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

Top 5 Cybersecurity Events of the Week: Barracuda Root Exploits, cPGuard Supply-Chain Attack, APT Flaw, Xen Escape Bugs, and OpenSSH Authentication Bypass

This week’s Jet CSIRT roundup highlights five critical security issues affecting widely deployed infrastructure. Two high-severity vulnerabilities in Barracuda Email Security Gateway and other appliances allow unauthenticated attackers to obtain root access via authorization bypass and command injection. A supply-chain compromise of cPGuard versions 5.88.12–5.88.19 enabled theft of password hashes, database files, and SSH keys from at least 32 customer servers before the malicious update was removed. A flaw in the APT package manager (CVE-2026-109518) lets network attackers substitute malicious packages that execute with root privileges on Debian and Ubuntu systems. Two Xen hypervisor bugs (CVE-2026-102703 and CVE-2026-102704) permit a compromised guest VM to read and write memory belonging to dom0 and other guests. Finally, an OpenSSH authentication bypass on musl-based Alpine Linux distributions allows passwordless login to key-only accounts when long password hashes trigger a crypt() return value of “*”.

BoletimSec•Vulnerabilities & Exploits

CISA and FBI Warn of Global Cyber Attacks on Industrial Refrigeration and Cold Chain Controllers

CISA, the FBI, and multiple U.S. agencies issued a joint advisory on November 5 detailing malicious cyber activity targeting industrial refrigeration systems and cold chain monitoring equipment worldwide. Attackers are exploiting unpatched or internet-exposed temperature controllers in supermarkets and cold storage facilities through authentication bypass, arbitrary code injection, and weak configurations. Once inside the control panels, threat actors force units into continuous heating and defrost cycles, the opposite of their intended function, while also causing denial of visibility that prevents operators from seeing real equipment status. The advisory highlights risks including reduced system lifespan, fire hazards, stock loss, and potential consumer harm from spoiled products stored outside safe temperature ranges. Sectors most affected include public health, chemical manufacturing, food and agriculture, and refrigerated transportation. Recommended mitigations focus on network segmentation, removal of remote access from the public internet, strong authentication, firmware updates, and regular offline backups.

BoletimSec•Vulnerabilities & Exploits

Critical Flaw in React Server Components Enables Unauthenticated Remote Code Execution

The React team disclosed security advisory GHSA-xqc2-xf4c-x3h3 describing a high-impact vulnerability in React Server Components that can lead to remote code execution. The flaw affects packages react-server-dom-webpack, react-server-dom-parcel, and react-server-dom-turbopack across multiple version ranges from 19.0.0 through 19.3.0. Exploitation requires no authentication, privileges, or user interaction, allowing a remote attacker to execute code on the server by sending a specially crafted request containing multiple typed arrays alongside attacker-controlled data. No CVE identifier was assigned, and the advisory notes that the issue is distinct from the previously reported React2Shell vulnerability tracked as CVE-2025-55182. Affected applications are limited to those running React code on the server with supported frameworks and bundlers; client-only React usage is unaffected. Patches are available in versions 19.0.9, 19.1.10, 19.2.9, and 19.3.1, with immediate updates strongly recommended. The React team also linked similar typed-array handling issues in Next.js Cache Components, suggesting a broader class of errors.

Security NEXT•Vulnerabilities & Exploits

Plex Media Server Vulnerabilities Exploited in Wild via Plex2Shell Chain

Plex has disclosed active exploitation of four vulnerabilities in Plex Media Server versions 1.43.2 and earlier. The flaws, tracked as CVE-2026-96652, CVE-2026-96654, CVE-2026-96655 and CVE-2026-96656, allow unauthenticated remote code execution when chained together. Attackers are leveraging server-side request forgery and token-handling weaknesses to write arbitrary files on exposed servers. Proof-of-concept code named Plex2Shell was published on 16 October, after which CISA added the issues to its Known Exploited Vulnerabilities catalog. Compromised systems have been observed deploying cryptocurrency miners and proxy relays. The software is widely used both as a standalone media server and as an add-on for QNAP and other NAS devices, increasing the potential attack surface.