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)
Fri, Nov 8, 3:02 AM
Unknown Object (File)
Wed, Nov 6, 1:08 PM
Unknown Object (File)
Tue, Oct 22, 6:03 AM
Unknown Object (File)
Thu, Oct 17, 6:12 PM
Unknown Object (File)
Thu, Oct 17, 6:08 PM
Unknown Object (File)
Thu, Oct 17, 6:08 PM
Unknown Object (File)
Thu, Oct 17, 6:05 PM
Unknown Object (File)
Thu, Oct 17, 5:36 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

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

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.