Page MenuHomeFreeBSD

usr.bin/sort: Avoid UBSan errors
ClosedPublic

Authored by arichardson on Jul 3 2021, 3:10 PM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, May 15, 1:11 AM
Unknown Object (File)
Fri, Apr 26, 11:48 AM
Unknown Object (File)
Tue, Apr 23, 2:16 PM
Unknown Object (File)
Apr 19 2024, 3:50 AM
Unknown Object (File)
Apr 19 2024, 3:50 AM
Unknown Object (File)
Apr 19 2024, 3:50 AM
Unknown Object (File)
Apr 19 2024, 3:35 AM
Unknown Object (File)
Feb 7 2024, 7:09 PM
Subscribers
None

Details

Summary

UBSan complains about out-of-bounds accesses for zero-length arrays. To
avoid this we can use flexible array members. However, the C standard does
not allow for structures that only contain flexible array members, so we
move the length parameters into that structure too.

Split out from D28233.

Diff Detail

Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 40251
Build 37140: arc lint + arc unit

Event Timeline

arichardson created this revision.
markj added inline comments.
usr.bin/sort/bwstring.c
170

Why is it + 2?

usr.bin/sort/bwstring.h
78

Can't this be mb_cur_max instead? I guess it ought to be irrelevant since both branches do the same thing.

This revision is now accepted and ready to land.Jul 5 2021, 12:24 PM
usr.bin/sort/bwstring.c
170

Why is it + 2?

I am not sure about this, I would assume + 1 is sufficient for the zero char, but I didn't want to change the existing code in case something depends on the + 2.

usr.bin/sort/bwstring.h
78

Ah good catch, I missed this one while rebasing.

usr.bin/sort/bwstring.c
170

Yeah, better not to change it. I just stared at it for a while and couldn't see why + 1 wasn't enough.

This revision was automatically updated to reflect the committed changes.