mirror of https://github.com/OISF/suricata
util: fix fallback memrchr() implementation
The fallback memrchr() implementation initialized the search pointer to the one-past-end position and dereferenced it before decrementing, which is undefined behavior in C. Update the implementation to decrement the pointer before dereferencing while preserving memrchr() semantics. Compare bytes using unsigned char semantics to ensure values with the high bit set are handled correctly. Refactor the fallback into a local SCMemrchrFallback() helper so it can be exercised by unit tests on platforms that provide a native memrchr() implementation. Expand the unit test to cover first, middle, last, duplicate, single-byte, zero-length, absent-element, and high-byte values. Ticket: 9010 Signed-off-by: Urval Kheni <kheniurval777@gmail.com>pull/16185/head
parent
c608165c04
commit
b475cc25b6
Loading…
Reference in New Issue