liveBook · Manning

Buffer overread

As explained in Hacking Cryptography

A buffer overread occurs when software reads beyond the valid contents or allocated bounds of a memory buffer.

A buffer overread occurs when software reads beyond the valid contents or allocated bounds of a memory buffer. It can expose data from adjacent memory that the requester was never allowed to access. section 10.6

Heartbleed heartbeat request

A TLS heartbeat normally echoes a declared 12-byte payload. A malicious client can declare thousands of bytes while supplying only a few; the server then reads beyond the heartbeat input and returns nearby memory, potentially exposing private keys. section 10.6

Prevent buffer overreads by:

  • Validating declared lengths against the actual available input before copying or echoing data. section 10.6
  • Avoiding unsafe functions such as strcpy(), sprintf(), gets(), and scanf(); prefer alternatives requiring explicit buffer bounds. section 10.6
  • Treating memcpy() as bounds-neutral: it copies blindly, so the programmer must establish both source and destination limits. section 10.6

How Hacking Cryptography covers it

How deep it goes
Traces attacker-controlled length parsing through memcpy and identifies missing validation, then stops at defensive coding guidance.
Examples
Uses the Heartbleed heartbeat exchange, OpenSSL 1.0.1f code, and unsafe-versus-safer C/C++ string and input functions.
What it assumes
Assumes familiarity with C/C++ buffers, pointers, lengths, and TLS heartbeat messages.
What you can do after
Diagnose buffer overreads by comparing declared lengths with available input and enforce explicit bounds before copying.
How it connects
Connects buffer overreads with memory safety, buffer management, TLS, Heartbleed, and unsafe C/C++ functions.

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.