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.
-
Validate lengths and sizes against the target type range before conversion, and check allocation results before use.
Seen in 4 reports
-
Validate lengths before reading so parsers cannot read past the end of a buffer.
Seen in 4 reports
-
Validate object lifetime before use, check lengths and bounds before copying, and bound size calculations to prevent overflow.
Seen in 4 reports
-
Validate pointers received from callers or network responses before dereferencing them.
Seen in 4 reports
-
Validate pointers received from remote peers or attacker input before dereferencing them.
Seen in 4 reports
-
Validate size and count values and use safe arithmetic before allocating buffers.
Seen in 4 reports
-
Validate size and offset arithmetic so integer overflow or underflow cannot wrap into unsafe values.
Seen in 4 reports
-
Validate size and structure fields from files against the allocated buffer before reading or writing.
Seen in 4 reports
-
Validate that a caller-supplied value refers to legitimate memory before using it as a pointer.
Seen in 4 reports
-
Validate the minimum and maximum size of every field taken from a packet before casting or copying it.
Seen in 4 reports
-
Validate the size and length of user-supplied data before writing or copying it into buffers.
Seen in 4 reports
-
Validate the size and structure of embedded font data against the destination buffer before reading or writing.
Seen in 4 reports
-
Validate the type of array elements before processing them.
Seen in 4 reports
-
Validate user-supplied lengths and check for overflow before allocating buffers.
Seen in 4 reports
-
Validate user-supplied lengths before size calculations and use checked arithmetic to prevent overflow and underflow.
Seen in 4 reports
-
Add bounds checks before reading or writing user-supplied lengths and dimensions, as the platform advisories state for the audio, image and HID fixes.
Seen in 3 reports
-
Add bounds checks on input lengths and manage object lifetimes so freed objects cannot be reused.
Seen in 3 reports
-
Add improved checks on the type of user-supplied data before use.
Seen in 3 reports
-
Cancel pending callbacks and re-check object liveness after nested event loops and asynchronous operations.
Seen in 3 reports
-
Check a length variable for zero before decrementing it.
Seen in 3 reports
-
Check every file-controlled size and length against the remaining buffer before copying or advancing pointers.
Seen in 3 reports
-
Check for integer overflow when multiplying counts by structure sizes before allocating.
Seen in 3 reports
-
Check for null pointers before dereferencing.
Seen in 3 reports
-
Check for underflow before decrementing length counters and allocate arrays based on the number of elements actually parsed.
Seen in 3 reports
-
Check integer arithmetic for overflow, wraparound and underflow before using the result.
Seen in 3 reports
-
Check multiplications and sums of counts and sizes for integer overflow before allocating buffers.
Seen in 3 reports
-
Check object liveness after any call that can run script or destroy the object, and avoid using this afterwards.
Seen in 3 reports
-
Check size calculations for overflow and underflow before allocating or writing.
Seen in 3 reports
-
Check size calculations for overflow before allocating, and use the checked result for the copy loop.
Seen in 3 reports
-
Check that a fallback format is compatible with the original and keep hardened attributes on backend contexts.
Seen in 3 reports
-
Check that an object still exists before using it in the parser.
Seen in 3 reports
-
Check that an object still exists before using it in xfrm_dev_state_delete, cifs_newfile_info and the HIDPP connect-event path.
Seen in 3 reports
-
Check that an object still exists before using or freeing it to prevent use-after-free and double-free.
Seen in 3 reports
-
Check that the referenced object still exists before the action handler operates on it.
Seen in 3 reports
-
Check that two characters follow a percent sign before shifting the string.
Seen in 3 reports
-
Check user-supplied indices and lengths against the actual array or buffer size before access.
Seen in 3 reports
-
Correct how objects are handled in memory and re-check references after callbacks that can run script.
Seen in 3 reports
-
Correct reference count handling so objects are not freed while still in tables or queues.
Seen in 3 reports
-
Detach or clear references when freeing objects, and set freed pointers to null.
Seen in 3 reports
-
Hold a reference or lock around objects for their whole lifetime and check existence before use after free.
Seen in 3 reports
-
Hold a reference to objects while callbacks can run.
Seen in 3 reports
-
Improve bounds checking and input validation before writing to memory buffers while parsing images.
Seen in 3 reports
-
Improve input validation when parsing media and document files so malformed fields cannot drive memory corruption.
Seen in 3 reports
-
Improve memory handling and memory management to prevent double frees and corruption.
Seen in 3 reports
-
Initialise pointers before use and validate user-supplied values before treating them as pointers.
Seen in 3 reports
-
Initialise resources before use so uninitialised memory is never read.
Seen in 3 reports
-
Initialise variables and pointers before use, including mapping structures passed to unmap.
Seen in 3 reports
-
Keep type and side-effect assumptions sound when optimising, including across reoptimisation.
Seen in 3 reports
-
Parsers should validate the length and content of user-supplied data before copying it into fixed-size buffers.
Seen in 3 reports
-
Re-check that an object still exists after synchronous callbacks and nested event loops before dereferencing it.
Seen in 3 reports