Commit ebbd5fdc authored by Matthew Fernandez's avatar Matthew Fernandez
Browse files

fix: remove 'sizeof(refcounted_ptr_t) == sizeof(refcounted_ptr)' assumptions

As encoded in a static assertion, the verifier assumes

  sizeof(refcounted_ptr_t) >= sizeof(struct refcounted_ptr)

However, some locations were implicitly assuming something stronger, that these
two were equally sized. This stronger property is true on most platforms – the
double word used for `refcounted_ptr_t` is exactly the same size as the
reference-counted pointer struct – but on esoteric platforms it may not be. If a
pointer is e.g. 2 bytes, the struct may end up being 4 bytes while
`refcounted_ptr_t` is 8 bytes.

To remedy this we need to:

  1. Always use `sizeof(struct refcounted_ptr)` in `memcpy` sizes in preference
     to `sizeof(refcounted_ptr_t)` to avoid over-reading/-writing; and

  2. Zero-initialise `refcounted_ptr_t` variables into which we are about to
     perform a (possibly short) `memcpy`.
parent 3a37c02d
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment