libsframe: adjust an incorrect check in flip_sframe
authorIndu Bhagat <indu.bhagat@oracle.com>
Fri, 6 Jan 2023 17:29:48 +0000 (09:29 -0800)
committerIndu Bhagat <indu.bhagat@oracle.com>
Mon, 9 Jan 2023 17:47:24 +0000 (09:47 -0800)
commit2ffa66fc9f2a23119e799455f6f94ade8d710d3f
treecfeef80cf216b09a0509e9fd8308422162a09af4
parentdcaa0ed8f6f486d49b8b3b7ee0da8a80f64affbd
libsframe: adjust an incorrect check in flip_sframe

When sframe_encoder_write needs to flip the buffer containing the SFrame
section before writing, it is not necessary that the SFrame FDES are in
the order of their sfde_func_start_fre_off.  On the contrary, SFrame
FDEs will be sorted in the order of their start address.  So, remove
this incorrect assumption which is basically assuming that the last
sfde_func_start_fre_off seen will help determine the end of the flipped
buffer.

The function now keeps track of the bytes_flipped and then compares it with
the expected value.  Also, added two more checks at appropriate places:
 - check that the SFrame FDE read is within bounds
 - check that the SFrame FRE read is within bounds

libsframe/

* sframe.c (flip_sframe): Adjust an incorrect check.
Add other checks to ensure reads are within the buffer size.

(cherry picked from commit cd9aea32cffd8089f6f63f4eb86d4dccfc0b3850)
libsframe/sframe.c