laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmo-e1d/+/27800 )
Change subject: RIFO: Fix issue in frame number bounds checking ......................................................................
RIFO: Fix issue in frame number bounds checking
You can't have a 'min' and 'max' FN because of the wrap around this needs to be checked "all at once".
Signed-off-by: Sylvain Munaut tnt@246tNt.com Change-Id: Ie9024f84f79b458248786bca2343a1f8bffb9994 --- M src/octoi/frame_rifo.c M src/octoi/frame_rifo.h 2 files changed, 5 insertions(+), 10 deletions(-)
Approvals: Jenkins Builder: Verified laforge: Looks good to me, approved
diff --git a/src/octoi/frame_rifo.c b/src/octoi/frame_rifo.c index 7e8ddf7..9f25cf0 100644 --- a/src/octoi/frame_rifo.c +++ b/src/octoi/frame_rifo.c @@ -112,7 +112,7 @@ uint32_t bucket; uint8_t *dst;
- if (fn > frame_rifo_max_in_fn(rifo) && fn < frame_rifo_min_in_fn(rifo)) + if (!frame_rifo_fn_in_range(rifo, fn)) { return -ERANGE; } diff --git a/src/octoi/frame_rifo.h b/src/octoi/frame_rifo.h index f107537..6988710 100644 --- a/src/octoi/frame_rifo.h +++ b/src/octoi/frame_rifo.h @@ -13,16 +13,11 @@ indexed by physical offset in buf */ };
-/* maximum frame number we currently can store in the rifo */ -static inline uint32_t frame_rifo_max_in_fn(const struct frame_rifo *ff) +/* can this frame number be stores in the rifo */ +static inline bool frame_rifo_fn_in_range(const struct frame_rifo *ff, uint32_t fn) { - return ff->next_out_fn + FRAMES_PER_FIFO - 1; -} - -/* minimum frame number we currently can store in the rifo */ -static inline uint32_t frame_rifo_min_in_fn(const struct frame_rifo *ff) -{ - return ff->next_out_fn - 1; + uint32_t d = fn - ff->next_out_fn; + return d < FRAMES_PER_FIFO; }