Page MenuHomeFreeBSD

usr.bin/sort: Avoid UBSan errors
ClosedPublic

Authored by arichardson on Jul 3 2021, 3:10 PM.
Tags
None
Referenced Files
F81623686: D31009.id.diff
Fri, Apr 19, 3:50 AM
F81623683: D31009.id91866.diff
Fri, Apr 19, 3:50 AM
F81623680: D31009.id91699.diff
Fri, Apr 19, 3:50 AM
F81623050: D31009.diff
Fri, Apr 19, 3:35 AM
Unknown Object (File)
Feb 7 2024, 7:09 PM
Unknown Object (File)
Dec 20 2023, 3:17 AM
Unknown Object (File)
Dec 17 2023, 6:09 PM
Unknown Object (File)
Dec 11 2023, 3:36 AM
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.