Page MenuHomeFreeBSD

usr.bin/sort: Avoid UBSan errors
ClosedPublic

Authored by arichardson on Jul 3 2021, 3:10 PM.

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
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

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

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
169

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
169

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.