HomeFreeBSD

rs: Fix a use after free.

Description

rs: Fix a use after free.

Using a pointer passed to realloc() after realloc() even for pointer
arithmetic is UB. It also breaks in practice on CHERI systems as
the updated value of 'sp' in this case would have had the bounds from
the old allocation.

This would be much cleaner if elem were a std::vector<char *>.

Reviewed by: brooks, emaste
Reported by: GCC -Wuse-after-free
Differential Revision: https://reviews.freebsd.org/D36831

(cherry picked from commit e5f2d5b35e79ddf995a8a5c782a7940ca2e05fdf)

Details

Provenance
jhbAuthored on Oct 5 2022, 11:47 PM
Reviewer
brooks
Parents
rG068c9d3de7c9: rs: Fix various harmless warnings.
Branches
Unknown
Tags
Unknown