These are the notes for Cybersecurity Fundamentals (defensive), episode 53. Episode 52 showed how a running program uses memory: the stack, the heap, pointers, stack frames and the return address, and that C does no bounds checking. Today we meet the bug classes that live in that memory, the ones behind roughly 70% of serious security flaws (Microsoft and Chromium, episode 52). We name each one, trigger it on a toy program on our own buffers, read the real output, and give it its official CWE number. Every term is defined the first time it appears; the Glossary at the end collects them.
Safety and scope. Everything here is defensive and educational. Every program is a small toy that works only on its own memory. We never target, scan, or attack any real system; we never write a working exploit for real software; and the one dangerous technique, control-flow hijacking, is described in words only, never built. Samples were run on 12 Nov 2026 in the SyntaxPilot compiler (gcc 13.3, -O2, with _FORTIFY_SOURCE on) for the live runs, and separately under gcc -fsanitize=address for the AddressSanitizer reports. Garbage values and addresses differ on every run.
The bugs you'll meet
| Problem | Bug class | CWE |
|---|---|---|
| 20 bytes written into a 16-byte box overwrite a flag | buffer overflow, out-of-bounds write | CWE-787, CWE-121/122 |
A length of -1 passes a "too big?" check |
integer overflow, signedness | CWE-190/191 |
| A cancelled order is read, then freed, again | use-after-free, double free | CWE-416, CWE-415 |
| A crash from NULL; a leftover value | NULL deref, uninitialised memory | CWE-476, CWE-457 |
| User text printed as a command | format string | CWE-134 |
| A heartbeat that trusts a claimed length | out-of-bounds read (Heartbleed) | CWE-125 |
Problem 1: buffer overflow
Real-life example: a paper form with a name box sized for 16 letters, and right next to it a box that says "approved: yes/no". Write a name longer than 16 letters and the ink runs into the approved box.
- A buffer (episode 52) is a block of memory, e.g.
char name[16]holds 16 characters. - A buffer overflow is writing more data into a buffer than it can hold, so the extra bytes land on whatever sits next to it in memory.
- An out-of-bounds (OOB) write changes memory outside the buffer; an OOB read reads memory outside it. The write is far more dangerous: it corrupts another variable (or, worst case, control data).
- Stack buffer overflow (CWE-121): the buffer is a local variable, so the overflow hits other locals in the same stack frame. Heap buffer overflow (CWE-122): the buffer came from
malloc, so the overflow hits other heap data.
Demo 1: 20 bytes into a 16-byte box
// A login record: a 16-byte name box, then an is_admin flag beside it.
#include <stdio.h>
#include <string.h>
struct Login { char name[16]; int is_admin; };
static void set_name(struct Login *r, const char *src, size_t n) {
memcpy(r->name, src, n); // copies n bytes, no bounds check
}
int main(void) {
setvbuf(stdout, NULL, _IONBF, 0);
struct Login r;
r.is_admin = 0;
size_t n = 4;
set_name(&r, "Ravi", n); // fits in name[16]
printf("name=%s is_admin=%d\n", r.name, r.is_admin);
volatile size_t big = 20; // attacker sends 20 bytes
set_name(&r, "AAAAAAAAAAAAAAAAAAA", big); // 20 > 16: spills over
printf("after 20 bytes: is_admin=%d\n", r.is_admin);
return 0;
}
Real output:
name=Ravi is_admin=0
after 20 bytes: is_admin=4276545
name[16] and is_admin are both locals, so they sit side by side in the stack frame. Copying 20 bytes writes 16 into name and the extra 4 straight onto is_admin, flipping it from 0 to a non-zero value. A non-zero flag means "admin": the attacker promoted themselves without knowing any password. We used memcpy with a length kept in a volatile size_t so the compiler's _FORTIFY_SOURCE guard couldn't catch it at compile time, exactly like the unchecked copies that cause real overflows.
The overflow family
| Variant | What it does |
|---|---|
| OOB write | changes a neighbouring variable (worst: can reach control data) |
| OOB read | leaks a neighbour's data (this is how Heartbleed worked) |
| off-by-one | one byte or element too far: i <= n, or forgetting a C string's \0 needs 1 extra byte |
| stack vs heap | locals vs malloc'ed memory |
The root cause is always the same: using a size (or index) the attacker controls, without checking it.
A tool that catches it: AddressSanitizer
AddressSanitizer (ASan) is a tool built into gcc and clang. Compile with -fsanitize=address and it checks every memory access at run time, stopping with an exact report instead of silently corrupting memory. The same overflow, built as char token[16] with a 19-letter name copied in via strcpy:
==9198==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7f57d3d00070 at pc 0x7f57d62a7923 bp 0x7ffcaa68d0d0 sp 0x7ffcaa68c878
WRITE of size 20 at 0x7f57d3d00070 thread T0
#1 0x5622c426534c in save_v1 name.c:7
#0 0x5622c42652b8 in save_v1 name.c:5
[32, 48) 'token' (line 6) <== Memory access at offset 48 overflows this variable
SUMMARY: AddressSanitizer: stack-buffer-overflow strcpy
It names the bug (stack-buffer-overflow), the size of the bad write, the exact source line, and the variable (token) that overflowed. We use ASan properly in episode 54.
Problem 2: integer overflow and signedness
Real-life example: a bouncer checks "is this number bigger than the limit?" A guest hands over -1. It's not bigger than the limit, so it passes, and later -1 is read as a gigantic size.
- An integer overflow (CWE-190) is a number growing past the largest value its type can hold and wrapping around. For a 32-bit signed
int,INT_MAX(2,147,483,647)+ 1wraps to the most negative value. Underflow (CWE-191) is the same at the bottom. - A signed integer can be negative (
int); an unsigned one cannot (size_t, the type used for sizes and lengths). The same bits mean different values: the pattern that is-1as a signedintis about 4.29 billion as an unsignedsize_t. - A signedness bug is treating the same value as signed in one place and unsigned in another, so a check and a use disagree.
Demo 2: a length of -1 passes a size check
// A length check that uses a signed int, then copies that many bytes.
#include <stdio.h>
#include <limits.h>
int buffer_ok_v1(int len) { // signed int: can be negative
char buf[64];
if (len > (int)sizeof buf) // "too big?" -- only checks the top
return 0; // reject
printf(" v1 len=%d accepted, will copy %d bytes\n", len, len);
return 1; // a negative len slips through
}
int buffer_ok_v2(size_t len) { // size_t: never negative
char buf[64];
if (len > sizeof buf) return 0;
printf(" v2 len=%zu accepted\n", len);
return 1;
}
int main(void) {
setvbuf(stdout, NULL, _IONBF, 0);
printf("INT_MAX = %d, so INT_MAX + 1 wraps:\n", INT_MAX);
int x = INT_MAX;
printf(" %d + 1 = %d\n", x, x + 1); // signed overflow
printf("v1 with len = -1 (sent as a huge number):\n");
buffer_ok_v1(-1); // passes the top check!
printf("v2 with len = -1 (read as size_t):\n");
buffer_ok_v2((size_t)-1); // becomes huge, rejected
return 0;
}
Real output:
INT_MAX = 2147483647, so INT_MAX + 1 wraps:
2147483647 + 1 = -2147483648
v1 with len = -1 (sent as a huge number):
v1 len=-1 accepted, will copy -1 bytes
v2 with len = -1 (read as size_t):
buffer_ok_v1 takes a signed int and only checks the top (len > sizeof buf). -1 is not greater than 64, so it's accepted, and if it were then used as a memcpy size, -1 becomes about 4 billion: a massive overflow. buffer_ok_v2 takes a size_t, so -1 arrives as that giant number and is rejected. Check sizes with an unsigned type, and check both ends (not too big, and not negative).
Problem 3: use-after-free and double free
Real-life example: a hotel. You check out and hand back the key (free), and the room is reused by the next guest (the next malloc). A use-after-free is keeping a copy of the key and walking back in; a double free is handing the same key back twice.
free(p)returns a heap block to the allocator (episode 52).- A dangling pointer (episode 52) still points at a block after it's freed.
- Use-after-free (CWE-416): using memory through a dangling pointer. The block may now belong to another part of the program, so you read or write someone else's data, and an attacker who controls what refills the block can make your program use their values.
- Double free (CWE-415): calling
freetwice on the same block, corrupting the allocator's bookkeeping.
Demo 3: use-after-free and double free
// An order is cancelled (freed). Two bugs follow.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
setvbuf(stdout, NULL, _IONBF, 0);
char *order = malloc(16);
strcpy(order, "2 chai mugs");
printf("order: %s\n", order);
free(order); // memory given back to the heap
// BUG 1: use-after-free. 'order' still points at the freed block.
char *note = malloc(16); // the heap may hand us the SAME block
strcpy(note, "SETTLED-0000");
printf("after free, order reads: %s\n", order); // now shows note's data
// BUG 2: double free. Freeing the same block twice.
free(order); // glibc detects this
printf("this line never prints\n");
return 0;
}
Real output:
order: 2 chai mugs
after free, order reads: Xfe
free(): double free detected in tcache 2
After free, reading order gives garbage: the allocator reused the block and wrote its own bookkeeping over our text. The second free is caught by glibc (the C library): double free detected in tcache 2, and the program aborts. A crash is the lucky case; the dangerous version refills the freed block with attacker data first. The fix is one line: set the pointer to NULL right after free, so any later use crashes loudly instead of silently.
Built with AddressSanitizer, the use-after-free is named exactly:
==9251==ERROR: AddressSanitizer: heap-use-after-free on address 0x502000000010 at pc 0x7fde070a1a6a bp 0x7ffc232ad0b0 sp 0x7ffc232ac828
READ of size 2 at 0x502000000010 thread T0
freed by thread T0 here:
#0 0x7fde070fc4d8 in free ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:52
previously allocated by thread T0 here:
#0 0x7fde070fd9c7 in malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
SUMMARY: AddressSanitizer: heap-use-after-free ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors_format.inc:563 in printf_common
It shows where the block was allocated, where it was freed, and where it was used after free, the trio you need to fix it.
Problem 4: NULL dereference and uninitialised memory
Two bugs about reading memory you shouldn't.
- NULL is a special pointer value meaning "points to nothing". Dereferencing a pointer means following it to the memory it points at (
*p, orp[0]). A NULL pointer dereference (CWE-476) follows a NULL pointer and crashes. It's usually a crash (a denial of service), not a takeover, but a crash in the wrong place still takes a service down. - Uninitialised memory (CWE-457) is reading a variable before giving it a value. In C a local variable starts with whatever happened to be in that memory, so the result is unpredictable.
Demo 4a: NULL pointer dereference
// Look up an order; the lookup returns NULL when it isn't found.
#include <stdio.h>
#include <stdlib.h>
char *find_order(int id) {
return NULL; // "not found"
}
int main(void) {
setvbuf(stdout, NULL, _IONBF, 0);
char *o = find_order(999);
printf("found pointer: %p\n", (void *)o);
printf("first char: %c\n", o[0]); // dereference NULL -> crash
return 0;
}
Real output:
found pointer: (nil)
Segmentation fault
find_order returns NULL ("not found"), the caller forgets to check, and o[0] follows the NULL pointer. Segmentation fault. Always check a pointer for NULL before using it.
Demo 4b: uninitialised memory
// A discount that is only set for gold customers.
#include <stdio.h>
int discount_for(int gold) {
int pct; // declared, NOT given a value
if (gold)
pct = 20; // set only on this path
return pct; // gold=0: returns whatever was here
}
int main(void) {
setvbuf(stdout, NULL, _IONBF, 0);
printf("gold customer: %d%% off\n", discount_for(1));
printf("normal customer: %d%% off\n", discount_for(0)); // garbage
return 0;
}
Real output:
gold customer: 20% off
normal customer: 20% off
pct is declared without a value and is set only on the gold path. For a normal customer that path is skipped, so pct is returned without being set, and it held the leftover 20 from the previous call: a normal customer gets a 20% discount they should never have. Give every variable a starting value before you read it.
Problem 5: format string bugs
printf's first argument is a format string:%dprints a number,%sa string,%pan address,%nwrites a number into memory.- A format string bug (CWE-134) is letting user input become that format string. With
%p/%xit reads values off the stack (an info leak); with%nit can write to memory.
Demo 5: user text as the format
// Printing a user-supplied label two ways.
#include <stdio.h>
int main(void) {
setvbuf(stdout, NULL, _IONBF, 0);
char secret[] = "PIN-4512"; // a value on the stack
const char *user = "%p %p %p %p"; // comes from the user
printf("v1 (user text as the format string):\n ");
printf(user); // BUG: user controls format
printf("\n");
printf("v2 (user text as DATA):\n ");
printf("%s", user); // safe: always prints it
printf("\n");
(void)secret;
return 0;
}
Real output:
main.c: In function 'main':
main.c:10:5: warning: format not a string literal and no format arguments [-Wformat-security]
10 | printf(user); // BUG: user controls format
| ^~~~~~
v1 (user text as the format string):
(nil) (nil) 0x27 0x7faebcae6380
v2 (user text as DATA):
%p %p %p %p
Version 1 passed the user's text (%p %p %p %p) as the format, so printf read four values off the stack and printed them, values the user was never meant to see. gcc even warned: format not a string literal. Version 2 printed the text as data with %s. Never pass user text as the format: always printf("%s", text).
Problem 6: Heartbleed (CVE-2014-0160)
Real-life example: a keep-alive "echo this back" where you send a word and claim a length, and the other side returns that many bytes, trusting your number.
- TLS (episode 22) is the lock on HTTPS. Its heartbeat extension (RFC 6520) lets one side send a small payload and a length; the other echoes the payload back to prove the connection is alive.
- The bug: affected versions of OpenSSL sized the reply from the claimed length, not the actual payload. So you could send a 4-byte word but claim 64 KB, and the server copied 64 KB back, the extra bytes being whatever sat next to the word in its memory: other users' passwords, session cookies, even the server's private key. It is an out-of-bounds read (CWE-125) handed straight to the attacker.
Demo 6: a toy heartbeat (our own memory, no network)
// A tiny "heartbeat": you send a word and a length; it echoes that many
// bytes back. The classic Heartbleed bug: it trusts the length.
#include <stdio.h>
#include <string.h>
char memory[64]; // our toy server's memory
void setup(void) {
memset(memory, 0, sizeof memory);
strcpy(memory, "ping"); // the word the client sent (4 bytes)
strcpy(memory + 20, "SECRET-KEY-42");// a secret sitting nearby in memory
}
void heartbeat_v1(int claimed_len) { // echoes claimed_len bytes, no check
printf(" v1 echoes %d bytes: ", claimed_len);
for (int i = 0; i < claimed_len; i++)
putchar(memory[i] ? memory[i] : '.');
printf("\n");
}
void heartbeat_v2(int actual_len, int claimed_len) { // checks the real size
if (claimed_len > actual_len) {
printf(" v2 refused: asked for %d but payload is %d\n",
claimed_len, actual_len);
return;
}
printf(" v2 echoes %d bytes: ", claimed_len);
for (int i = 0; i < claimed_len; i++) putchar(memory[i]);
printf("\n");
}
int main(void) {
setvbuf(stdout, NULL, _IONBF, 0);
setup();
printf("client sent the word \"ping\" (4 bytes) but claims 40:\n");
heartbeat_v1(40); // reads far past "ping" -> leaks
heartbeat_v2(4, 40); // checks: payload is only 4 bytes
return 0;
}
Real output:
client sent the word "ping" (4 bytes) but claims 40:
v1 echoes 40 bytes: ping................SECRET-KEY-42.......
v2 refused: asked for 40 but payload is 4
heartbeat_v1 echoes claimed_len bytes with no check, so claiming 40 for a 4-byte word leaks the nearby secret. heartbeat_v2 checks the real payload length first and refuses. This is Heartbleed in miniature, on our own buffer.
The real Heartbleed (facts fetched 12 Nov 2026):
- Affected OpenSSL 1.0.1 through 1.0.1f (and 1.0.2-beta); fixed in 1.0.1g.
- Publicly disclosed 7 April 2014, the day 1.0.1g was released. Reported by Google's Neel Mehta and found independently by Codenomicon. The flaw entered the code on 31 Dec 2011 and shipped in OpenSSL 1.0.1 on 14 March 2012.
- An attacker could read up to 64 KB of memory per heartbeat, repeatably. At disclosure, about 17% of trusted secure web servers (~half a million) were believed vulnerable.
- The fix was one added length check. (Sources: en.wikipedia.org/wiki/Heartbleed; US-CERT/CISA alert TA14-098A.)
The payoff, in concept only: control-flow hijacking
Episode 52 showed that a stack frame holds a function's local variables and its return address side by side. If an out-of-bounds write runs past a local and reaches the return address, and changes it, the function "returns" to an address the attacker chose, making the program run code of the attacker's choosing. That is control-flow hijacking. We only describe it; we never build one. The defences, stack canaries, DEP/NX, ASLR and more, are episode 55. This is why an OOB write is far worse than an OOB read: a read leaks, but a write can take control.
The bug-class map (CWE)
| Bug | CWE | Note |
|---|---|---|
| Out-of-bounds write | CWE-787 | #5 in the 2025 CWE Top 25 |
| Out-of-bounds read | CWE-125 | #8; Heartbleed is one |
| Use-after-free | CWE-416 | #7 |
| Double free | CWE-415 | |
| NULL pointer dereference | CWE-476 | usually a crash / DoS |
| Use of uninitialised variable | CWE-457 | |
| Integer overflow / wraparound | CWE-190 | underflow is CWE-191 |
| Uncontrolled format string | CWE-134 | |
| Stack-based buffer overflow | CWE-121 | |
| Heap-based buffer overflow | CWE-122 |
(CWE numbers are stable identifiers from cwe.mitre.org; the Top 25 ranks are from the 2025 list in episode 51.)
The whole chain
- 20 bytes in a 16-byte box → buffer overflow / OOB write.
len = -1passed the check → integer / signedness bug.- Read a cancelled order → use-after-free, double free.
- NULL and a leftover value → NULL deref, uninitialised memory.
- User text as the format → format string leak.
- A heartbeat trusted a length → Heartbleed (OOB read).
Every one is the same mistake: trusting data, a size, or a pointer you don't fully control.
Common mistakes (and what they cause)
| Mistake | Real message or result | Why | Fix |
|---|---|---|---|
memcpy(name, src, n) with n from outside |
is_admin is now: 4276545 |
no bounds check | check n <= sizeof name first |
if ((int)len > max) reject; |
v1 len=-1 accepted |
negative passes a > check |
use size_t; check both ends |
free(p); ... use(p); free(p); |
double free detected in tcache 2 |
dangling pointer, double free | p = NULL; right after free |
printf(user_text); |
(nil) (nil) 0x27 0x7fae... |
user controls the format | printf("%s", user_text) |
| read a local before setting it | a normal customer got 20% off | uninitialised memory | initialise at declaration |
| forget to check a returned pointer | Segmentation fault |
NULL dereference | if (p == NULL) ... |
Mini project: find and fix the four bugs
Take set_name, buffer_ok_v1, uaf.c and fmt.c from this episode and write a fixed version of each:
set_namemust refuse anynlarger thansizeof name.buffer_okmust usesize_tand reject both huge and negative lengths.- After every
free, set the pointer toNULL; confirm a later use now crashes immediately. - Every
printfof outside data must useprintf("%s", ...).
Build each fixed version with -fsanitize=address and confirm ASan reports no errors.
Practice
1. Add a size check to set_name so 20 bytes is refused.
Solution
static int set_name(struct Login *r, const char *src, size_t n) {
if (n >= sizeof r->name) return 0; // leave room for '\0' if needed
memcpy(r->name, src, n);
return 1; // 20 > 16 -> refused, is_admin stays 0
}
2. Change buffer_ok_v1 to size_t and re-test -1.
Answer
With size_t len, passing -1 arrives as about 4 billion, which is > sizeof buf, so it is rejected, exactly like buffer_ok_v2 in Demo 2.
3. Set order = NULL after free and watch it crash safely.
Answer
After free(order); order = NULL;, reading order later is a NULL dereference, which crashes immediately and loudly at the line of the bug, instead of silently reading reused memory. A loud crash near the bug is much easier to find and fix than silent corruption far from it.
4. Why is an out-of-bounds write worse than an out-of-bounds read?
Answer
A read leaks data (serious, e.g. Heartbleed). A write changes data, and if it reaches control data like the return address, it can make the program run the attacker's code (control-flow hijacking). A write can lead to full takeover; a read usually cannot.
Quick quiz
char buf[8];
int len = get_from_network(); // attacker controls len
if (len > 8)
return ERROR;
memcpy(buf, data, len); // copy len bytes
Which bug is this? A: use-after-free · B: format string · C: signed length: a negative len passes, then memcpy copies a huge amount · D: nothing is wrong.
Answer
C. len is a signed int. A negative len (e.g. -1) is not > 8, so it passes the check, but memcpy's size argument is unsigned, so -1 becomes about 4 billion: a huge out-of-bounds write. Fix: use size_t and check len is both <= 8 and not negative.
Interview questions
- What is a buffer overflow, and what's the difference between stack and heap overflow? Writing past a buffer's end. Stack overflow hits other locals and the return address in the same frame; heap overflow hits other heap allocations and allocator metadata.
- Why is an out-of-bounds write more dangerous than an out-of-bounds read? A read leaks data; a write can corrupt control data (the return address) and hijack execution.
- What is use-after-free, and how do you prevent it? Using memory through a pointer after it was freed. Prevent it by setting pointers to
NULLafterfree, clear ownership rules, and tools like AddressSanitizer; memory-safe languages prevent it by design. - How can an integer bug cause a buffer overflow? A signed length check can be passed by a negative value, which becomes a huge number when used as an unsigned size, so a later copy writes far past the buffer.
- What made Heartbleed possible, in one sentence? OpenSSL sized a TLS heartbeat reply from the attacker's claimed length instead of the actual payload, so the reply leaked adjacent memory (an out-of-bounds read, CWE-125).
- What is a format string vulnerability? Passing attacker-controlled text as
printf's format string, letting%x/%pread the stack or%nwrite memory. Fix:printf("%s", text). - Name three ways to find these bugs before shipping. AddressSanitizer/UBSan, Valgrind, static analysis and fuzzing (episode 54), plus compiler warnings and code review.
Glossary
| Term | Meaning |
|---|---|
| buffer | a block of memory, e.g. char name[16] |
| buffer overflow | writing more into a buffer than it holds; extra bytes hit the neighbour |
| out-of-bounds (OOB) write | writing outside a buffer; corrupts other data (CWE-787) |
| out-of-bounds (OOB) read | reading outside a buffer; leaks data (CWE-125) |
| off-by-one | one element/byte too far, e.g. i <= n, or forgetting the \0 |
| stack / heap buffer overflow | overflow of a local vs a malloc'ed buffer (CWE-121 / CWE-122) |
| AddressSanitizer (ASan) | a tool (-fsanitize=address) that catches memory errors at run time |
| integer overflow | a number wrapping past its type's maximum (CWE-190) |
| integer underflow | the same at the minimum (CWE-191) |
| signed / unsigned | an integer that can / cannot be negative (int vs size_t) |
| signedness bug | treating the same value as signed in one place, unsigned in another |
size_t |
the unsigned type used for sizes and lengths |
free |
return a heap block to the allocator |
| dangling pointer | a pointer to memory that has been freed |
| use-after-free | using memory through a dangling pointer (CWE-416) |
| double free | freeing the same block twice (CWE-415) |
| NULL | a pointer value meaning "points to nothing" |
| dereference | follow a pointer to the memory it points at (*p, p[0]) |
| NULL pointer dereference | following a NULL pointer; usually a crash (CWE-476) |
| uninitialised memory | reading a variable before giving it a value (CWE-457) |
| format string | printf's first argument: %d, %s, %p, %n |
| format string bug | letting user input be the format string (CWE-134) |
| TLS heartbeat | a TLS keep-alive (RFC 6520) that echoes a payload |
| Heartbleed | CVE-2014-0160: an OpenSSL heartbeat OOB read that leaked memory |
| control-flow hijacking | overwriting the return address to run attacker-chosen code (concept only) |
| CWE | Common Weakness Enumeration: the catalogue of weakness types (episode 8) |
_FORTIFY_SOURCE |
a gcc feature that adds some runtime size checks (episode 54) |
| glibc | the GNU C library; it detects some bugs like double free |
Summary
Memory corruption bugs come from a handful of mistakes: writing or reading past a buffer (overflows, off-by-one), getting a size wrong (integer overflow and signedness), using memory after it's freed (use-after-free, double free, dangling pointers), reading memory you shouldn't (NULL dereference, uninitialised memory), and letting input control a format string. Heartbleed was a single out-of-bounds read that leaked half a million servers' secrets because one length check was missing. The worst case, an out-of-bounds write that reaches the return address, is control-flow hijacking, which we described but never built. Each bug has a CWE number the whole industry shares. Next episode: secure coding in C and C++, the functions, flags and tools that stop every bug we met today.