liveBook · Manning

Buffer overflow

As explained in Hacking Cryptography

A buffer overwrite occurs when software writes beyond a buffer's valid bounds and changes adjacent memory.

A buffer overflow occurs when user-controlled data exceeds its allocated bounds and overwrites adjacent memory. If executable areas are changed, an attacker may take control of a server. section 10.6

Heartbeat memory failure

Heartbleed illustrates the related danger of unchecked lengths: a client requests a long heartbeat response while supplying little data, causing the server to read beyond its heartbeat buffer. In OpenSSL 1.0.1f, memcpy(bp, pl, payload) trusts the claimed payload length without validating the available input.

Reduce exposure by combining implementation discipline with platform defenses:

  • Avoid C/C++ functions without length checks, including strcpy(), sprintf(), gets(), and scanf(). section 10.6
  • Use bounded alternatives such as strncpy(), snprintf(), fgets(), and sscanf(); treat memcpy() as safe only when bounds are verified. section 10.6
  • Recognize mitigations such as address space layout randomization, data execution prevention, and stack canaries, alongside bypasses such as return-oriented programming. section 10.6

How Hacking Cryptography covers it

How deep it goes
Traces unchecked input through vulnerable C code and defenses, but stops short of a complete exploit.
Examples
Uses HTTP input, server memory, unsafe C functions, Heartbleed, and an OpenSSL heartbeat-processing listing.
What it assumes
Assumes familiarity with buffers, pointers, and C/C++ memory operations while teaching the security consequences concretely.
What you can do after
Diagnose/debug with it by checking lengths, replacing unsafe functions, and identifying reads or writes beyond allocated buffers.
How it connects
Connects buffer overflows with memory safety, Heartbleed, TLS, stack canaries, data execution prevention, and return-oriented programming.

Also explained in

Compare how 2 books explain buffer overflow →

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.