uds
uds copied to clipboard
Potentially incorrect normalization code in new_from_ffi
Caught during unsafe review
https://github.com/tormol/uds/blob/a5968947e08cc092b417f30f12bd3d9cf3b4c981/src/addr.rs#L647-L654
Some platforms, including FreeBSD, require a null terminator here, which we are sometimes stripping
e.g. FreeBSD:
The sun_path field must be terminated by a NUL character to be used with SUN_LEN(), but the terminating NUL is not part of the address.
We do have some code on OpenBSD that talks about this but it isn't involved here, and it's only OpenBSD, not FreeBSD as well.
https://github.com/tormol/uds/blob/a5968947e08cc092b417f30f12bd3d9cf3b4c981/src/addr.rs#L252-L257
I'd recommend we'd cautiously not strip the NUL except for specific platforms where we know that that's okay.
In general the NUL invariant is also hard to follow in this follow, would be worth documenting it more.