bcachefs: Array bounds fixes

It's no longer legal to use a zero size array as a flexible array
member - this causes UBSAN to complain.

This patch switches our zero size arrays to normal flexible array
members when possible, and inserts casts in other places (e.g. where we
use the zero size array as a marker partway through an array).

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet
2023-09-09 20:10:11 -04:00
parent a9a7bbab14
commit 5cfd69775e
7 changed files with 64 additions and 66 deletions

View File

@ -41,11 +41,11 @@
(round_up(vstruct_bytes(_s), 512 << (_sector_block_bits)) >> 9)
#define vstruct_next(_s) \
((typeof(_s)) ((_s)->_data + __vstruct_u64s(_s)))
((typeof(_s)) ((u64 *) (_s)->_data + __vstruct_u64s(_s)))
#define vstruct_last(_s) \
((typeof(&(_s)->start[0])) ((_s)->_data + __vstruct_u64s(_s)))
((typeof(&(_s)->start[0])) ((u64 *) (_s)->_data + __vstruct_u64s(_s)))
#define vstruct_end(_s) \
((void *) ((_s)->_data + __vstruct_u64s(_s)))
((void *) ((u64 *) (_s)->_data + __vstruct_u64s(_s)))
#define vstruct_for_each(_s, _i) \
for (_i = (_s)->start; \