Page MenuHomeFreeBSD

rs: Fix a use after free.
ClosedPublic

Authored by jhb on Sep 29 2022, 10:47 PM.
Tags
None
Referenced Files
F102729945: D36831.diff
Sat, Nov 16, 11:27 AM
Unknown Object (File)
Thu, Nov 7, 2:01 AM
Unknown Object (File)
Tue, Nov 5, 2:34 PM
Unknown Object (File)
Oct 16 2024, 2:25 PM
Unknown Object (File)
Oct 15 2024, 2:40 AM
Unknown Object (File)
Oct 14 2024, 12:04 PM
Unknown Object (File)
Oct 11 2024, 3:06 PM
Unknown Object (File)
Oct 10 2024, 4:55 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 Skipped
Unit
Tests Skipped
Build Status
Buildable 47645
Build 44532: arc lint + arc unit

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.