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, Nov 24, 11:44 PM
Unknown Object (File)
Sun, Nov 24, 5:06 AM
Unknown Object (File)
Thu, Nov 21, 7:19 AM
Unknown Object (File)
Tue, Nov 19, 1:32 PM
Unknown Object (File)
Sat, Nov 16, 2:35 PM
Unknown Object (File)
Sat, Nov 16, 1:21 PM
Unknown Object (File)
Sat, Nov 16, 11:27 AM
Unknown Object (File)
Thu, Nov 7, 2:01 AM
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.