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.
-
Clear and null structures freed during proxy CONNECT handling so later code does not reference them.
Seen in 2 reports
-
Clear callbacks and per-buffer state during device destruction before the underlying memory is freed.
Seen in 2 reports
-
Clear handler references when the context is garbage collected, not only on destruction, and lock handler list access between threads.
-
Clear native pointers in Java bridge objects when the C++ object is destroyed, and remove observers at the same time.
Seen in 2 reports
-
Consume the data marker even when the declared size is zero, and reject oversized length fields before allocation.
Seen in 2 reports
-
Copy or pin the container before iterating, or re-check the iterator after any call that can run script or callbacks.
Seen in 2 reports
-
Correct object handling in the Windows PDF library.
Seen in 2 reports
-
Correct object lifetime in animation timing updates and keyframe property reads.
-
Correct the bounds check in tiled region rectangle insertion.
Seen in 2 reports
-
Correct the garbage collection algorithm so unserialize cannot free an object still in use.
-
Delay reclamation of the shared IPv4 options object until existing readers finish, for example with RCU freeing.
-
Destroy connections and release references before deletion, and re-validate pointers after freeing arrays.
Seen in 2 reports
-
Do not call a second close function on a pointer already freed by the first.
-
Do not deserialise untrusted data into trusted object types, or validate its origin and content first.
-
Do not pass externally controlled data as a format string; use fixed format specifiers.
-
Do not use user-supplied strings as format specifiers.
-
Ensure error returns still perform cleanup and do not leave handles to be destroyed twice.
Seen in 2 reports
-
Flush queued data before detaching or freeing the transfer object.
Seen in 2 reports
-
Free a buffer with the same allocator that allocated it.
-
Give base classes virtual destructors so derived objects are deleted correctly.
-
Guard iteration against re-entrant mutation of the container, for example by copying the list or deferring removals.
Seen in 2 reports
-
Hold the guarding lock when reading members in destructors, and register pointers into compactable storage as movable references.
Seen in 2 reports
-
Improve bounds checking when parsing and rendering PDF content.
-
Improve input sanitisation and validation in the kernel.
-
Improve input validation before using user-supplied data.
-
Improve memory handling in the kernel.
-
Improve memory handling in the XSLT library.
-
Improve memory handling so objects are not used after being freed, as stated for the browser engine and process model fixes.
-
Improved validation, or removal of the vulnerable code.
-
Increase reference counts when storing objects and avoid releasing objects still referenced elsewhere.
-
Initialise memory buffers before use and release an updated build.
-
Initialise the iovector length field before processing a MAYBE call.
-
Keep the finished source handler list consistent when the active list is cleared, and do not erase a handler before calling a method on it.
-
Keep the provider library context alive until every SSL_CTX created from it has been destroyed, including connections on the shutdown list.
-
Limit the number of characters read into fixed-size buffers instead of using unbounded string formats.
Seen in 2 reports
-
Make cleanup code free each object once and only when it owns it.
Seen in 2 reports
-
Make the validation limit match the destination buffer size.
-
Manage object lifetimes when form field events trigger page deletion.
-
Pass the actual buffer length to the image converter and validate bitmap header fields before computing sizes.
-
Patch the PHP engine itself rather than the application, since the flaws sit in request parsing and cleanup before application code runs.
-
Place the setjmp checkpoint in the function that calls the decode routines so the handler frame is still live on longjmp.
-
Randomise code layout, blind constants and limit the number of executable regions per module.
Seen in 2 reports
-
Range-check parsed fields against the specification and verify data precision matches the output format before copying.
Seen in 2 reports
-
Re-fetch the socket entry after invoking a callback that may free it, as was done in the update leg.
-
Re-run variable collection and loop classification after optimisation passes that remove or reclassify nodes.
Seen in 2 reports
-
Re-validate the result kind after side effects and keep receiver type checks in optimisations.
Seen in 2 reports
-
Recreate or resize encoder state when layer counts or macroblock grids change instead of reusing stale configuration.
Seen in 2 reports
-
Reject non-positive kernel unit lengths in the filter attribute setters rather than relying on debug assertions.
-
Reserve space for the null terminator and use a greater-or-equal comparison so a value exactly equal to the buffer size is rejected.
-
Reset handles and cookies to null after closing or completing an operation.
Seen in 2 reports