In-depth lesson · Memory corruption
Typical fixes
Every point the Memory corruption reports back under this heading, best-backed first, each with the reports it is seen in.
-
Check for integer overflow before resizing buffers and validate length fields against the destination size.
Seen in 4 reports
-
Check for integer overflow before using a computed size for allocation.
Seen in 4 reports
-
Check for integer overflow in size calculations and grow the value stack before copying arguments.
Seen in 4 reports
-
Check header and field lengths before copying into fixed-size stack buffers.
Seen in 4 reports
-
Check size arithmetic for overflow and truncation before allocating buffers.
Seen in 4 reports
-
Check size calculations for integer overflow and keep the allocation size and copy size derived from the same checked value.
Seen in 4 reports
-
Check size multiplications and subtractions for overflow before allocating buffers.
Seen in 4 reports
-
Check tag-supplied lengths and counters against the destination buffer size before copying or indexing.
Seen in 4 reports
-
Check that a length is at least the fixed header size before subtracting from it, and use checked arithmetic for allocation sizes.
Seen in 4 reports
-
Check that an object still exists before dereferencing it during parsing.
Seen in 4 reports
-
Check that an object still exists before operating on it, and avoid destroying a shared parent while other callbacks still reference it.
Seen in 4 reports
-
Check that an object still exists before operating on it, and use lifetime-aware references for callbacks.
Seen in 4 reports
-
Check that an object still exists before using it, and null out pointers after freeing.
Seen in 4 reports
-
Check that an object still exists before using it, to prevent use-after-free.
Seen in 4 reports
-
Check that an object still exists before using or freeing it, and clear references after release.
Seen in 4 reports
-
Check the length of user-supplied data before copying it into a fixed-length heap buffer.
Seen in 4 reports
-
Check user-supplied lengths against the actual buffer size before copying.
Seen in 4 reports
-
Clear references when an object is freed and validate that an object still exists before using it.
Seen in 4 reports
-
Correct object handling in kernel-mode drivers to prevent memory corruption.
Seen in 4 reports
-
Correct object lifetime handling so freed memory is not referenced again.
Seen in 4 reports
-
Do not iterate live containers across calls that can run script or re-enter; copy the keys first or hold owning references.
Seen in 4 reports
-
Enforce state and size checks in release builds, not only through debug assertions.
Seen in 4 reports
-
Hold reference-counted handles rather than raw pointers in callbacks, and iterate copies of containers that can be mutated during the loop.
Seen in 4 reports
-
Improve memory handling in the affected framework.
Seen in 4 reports
-
Improve memory handling so freed or wrongly typed objects are not reused.
Seen in 4 reports
-
Improve memory management and locking to close use-after-free and race conditions.
Seen in 4 reports
-
Improve memory management so freed objects are not referenced again.
Seen in 4 reports
-
Initialise memory and resources before use.
Seen in 4 reports
-
Initialise memory before it is read or used.
Seen in 4 reports
-
Initialise memory before use and check that required elements are present.
Seen in 4 reports
-
Initialise pointers before use.
Seen in 4 reports
-
Mark pipe pages attached to network buffers as shared, and verify that decryption targets memory the buffer owns.
Seen in 4 reports
-
Perform size calculations in wider arithmetic and check for overflow before allocating.
Seen in 4 reports
-
Reject zero, negative and oversized length fields and check allocation results before use.
Seen in 4 reports
-
Security update corrects how the Windows Runtime handles objects in memory.
Seen in 4 reports
-
Serialise access to shared state on the owning sequence or use atomic reference counts.
Seen in 4 reports
-
Treat all guest-supplied data as untrusted and validate it in virtual device emulation.
Seen in 4 reports
-
Use bounded string copying and check parameter lengths before copying into fixed buffers.
Seen in 4 reports
-
Use checked 64-bit arithmetic for buffer size calculations.
Seen in 4 reports
-
Use overflow-checked or unsigned arithmetic in size and offset calculations.
Seen in 4 reports
-
Use overflow-checked size arithmetic in document filter parsers.
Seen in 4 reports
-
Use weak pointers or validity checks after synchronous calls that can destroy the object, and remove objects from global sets in their destructors.
Seen in 4 reports
-
Use weak references or liveness checks after callbacks that can synchronously destroy objects.
Seen in 4 reports
-
Use wide enough size types and check for overflow, underflow and truncation in size calculations.
Seen in 4 reports
-
Validate a user-supplied value before using it as a memory pointer.
Seen in 4 reports
-
Validate attacker-controlled sizes and counts before using them in pointer arithmetic or copies.
Seen in 4 reports
-
Validate file-supplied sizes, counts and offsets against the actual buffer before any read or write.
Seen in 4 reports
-
Validate length and index fields in SMB requests and initialise pointers on all paths.
Seen in 4 reports
-
Validate length and size fields against the destination buffer before copying, and check arithmetic for overflow before allocating.
Seen in 4 reports
-
Validate length, size and offset fields from input against the destination buffer before copying or reading.
Seen in 4 reports