diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-09-04 16:35:56 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-04 16:35:56 +0000 |
commit | 16624668d40cb3f8545188d95f96d635313d5479 (patch) | |
tree | a1e6151e093515698c7c6463016421bd097a1dc1 /src/sys/socket | |
parent | 01f4d57eede3ed2f1051778113b1d6a7dff8e9d6 (diff) | |
parent | 39d158a0142d8a9f38d7952a686cb53fa6542a5f (diff) | |
download | nix-16624668d40cb3f8545188d95f96d635313d5479.zip |
Merge #1120
1120: Fix length of abstract socket address r=asomers a=yshui
NULL bytes have no special significance in an abstrace address, and the
length of the address is solely decided by the length member. If the
length is set to sun_path.len(), all the NULL bytes will be considered
part of the address.
Tests are updated accordingly.
Closes #1119
Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
Co-authored-by: Yuxuan Shui <yshuiv7@gmail.com>
Diffstat (limited to 'src/sys/socket')
-rw-r--r-- | src/sys/socket/addr.rs | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs index 2ad453f7..7037ae47 100644 --- a/src/sys/socket/addr.rs +++ b/src/sys/socket/addr.rs @@ -560,7 +560,7 @@ impl UnixAddr { ret.sun_path.as_mut_ptr().offset(1) as *mut u8, path.len()); - Ok(UnixAddr(ret, ret.sun_path.len())) + Ok(UnixAddr(ret, path.len() + 1)) } } @@ -1298,7 +1298,7 @@ mod tests { let addr = UnixAddr::new_abstract(name.as_bytes()).unwrap(); let sun_path1 = addr.sun_path(); - let sun_path2 = [0u8, 110, 105, 120, 0, 97, 98, 115, 116, 114, 97, 99, 116, 0, 116, 101, 115, 116, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + let sun_path2 = [0u8, 110, 105, 120, 0, 97, 98, 115, 116, 114, 97, 99, 116, 0, 116, 101, 115, 116]; assert_eq!(sun_path1.len(), sun_path2.len()); for i in 0..sun_path1.len() { assert_eq!(sun_path1[i], sun_path2[i]); |