Page MenuHomeFreeBSD

rs: Fix a use after free.
ClosedPublic

Authored by jhb on Sep 29 2022, 10:47 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Apr 7, 12:28 PM
Unknown Object (File)
Feb 14 2024, 4:59 AM
Unknown Object (File)
Dec 23 2023, 1:55 AM
Unknown Object (File)
Dec 12 2023, 8:27 AM
Unknown Object (File)
Aug 26 2023, 8:28 AM
Unknown Object (File)
Jun 23 2023, 5:09 PM
Unknown Object (File)
May 6 2023, 9:39 AM
Unknown Object (File)
Mar 16 2023, 3:11 PM
Subscribers

Details

Summary

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 *>.

Reported by: GCC -Wuse-after-free

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

jhb requested review of this revision.Sep 29 2022, 10:47 PM

@brooks It is interesting that GCC 12 now warns about this type of UB with realloc().

The "you can't even do math" thing always seems excessive, but if gcc is going to warn on it then at least it will clean up all the CHERI realloc issues.

This revision is now accepted and ready to land.Sep 29 2022, 10:57 PM
This revision was automatically updated to reflect the committed changes.