liveBook · Manning

Memory-safe language

As explained in Hacking Cryptography

A memory-safe language is a programming language that prevents or detects invalid memory accesses through its language rules, runtime, or implementation.

A memory-safe language prevents or detects invalid memory accesses through language rules, runtime checks, or implementation safeguards. It reduces failures such as out-of-bounds reads, use-after-free, uninitialized memory, and double freeing. section 10.6

The security risk is concrete: a client-controlled length can exceed the received data, causing memcpy() to read beyond a buffer and expose sensitive server memory. Heartbleed demonstrates how missing bounds checks turn ordinary message handling into information disclosure. section 10.6

Practical guidance:

  • Prefer memory-safe languages such as C#, Rust, Go, Java, Swift, or JavaScript where possible. section 10.6
  • When C or C++ is unavoidable, maximize test coverage and fuzz extensively to find memory-safety defects. section 10.6
Figure 10.9 The Heartbleed vulnerability: a malicious client requests a very long heartbeat but provides very little data to echo. The vulnerable server reads beyond the heartbeat buffer into other areas of memory.
figure

Trace how a malicious heartbeat requests more data than it supplies, prompting an out-of-bounds read. section 10.6

How Hacking Cryptography covers it

How deep it goes
Connects language choice to buffer overreads, memory errors, and fuzzing, but does not explain language-runtime internals.
Examples
Uses OpenSSL 1.0.1f heartbeat code and Heartbleed to demonstrate length confusion and out-of-bounds memory reads.
What you can do after
Apply memory-safe languages where possible, or diagnose memory defects with extensive testing and fuzzing in C and C++.
How it connects
Connects memory safety with buffer overflow, use-after-free, double free, uninitialized memory, constant-time algorithms, and fuzzing.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Hacking Cryptography. The section links point to the parts of the book it draws on.