Page MenuHomeFreeBSD

rs: Fix a use after free.
ClosedPublic

Authored by jhb on Sep 29 2022, 10:47 PM.
Tags
None
Referenced Files
F84304613: D36831.id111251.diff
Wed, May 22, 2:11 AM
Unknown Object (File)
Sat, May 18, 10:48 AM
Unknown Object (File)
Sat, May 18, 10:48 AM
Unknown Object (File)
Fri, May 17, 6:37 PM
Unknown Object (File)
Fri, May 3, 10:10 PM
Unknown Object (File)
Thu, Apr 25, 2:54 PM
Unknown Object (File)
Apr 7 2024, 12:28 PM
Unknown Object (File)
Feb 14 2024, 4:59 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.