-
Notifications
You must be signed in to change notification settings - Fork 10
Open
Description
Caught during unsafe review
Lines 647 to 654 in a596894
// normalize addr.len to include terminating NUL byte if possible | |
// and not be greater than capacity | |
if addr.len >= capacity { | |
addr.len = capacity; | |
} else if addr.addr.sun_path[(addr.len-1-path_offset()) as usize] != 0 { | |
addr.len += 1; | |
addr.addr.sun_path[(addr.len-1-path_offset()) as usize] = 0; | |
} |
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.
Lines 252 to 257 in a596894
/// Is the size of the underlying `sun_path` field, | |
/// minus 1 if the OS is known to require a trailing NUL (`'\0'`) byte. | |
pub fn max_path_len() -> usize { | |
mem::size_of_val(&Self::new_unspecified().addr.sun_path) | |
- if cfg!(target_os="openbsd") {1} else {0} | |
} |
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.
Metadata
Metadata
Assignees
Labels
No labels