diff options
author | Yuxuan Shui <yshuiv7@gmail.com> | 2019-09-04 13:32:26 +0100 |
---|---|---|
committer | Yuxuan Shui <yshuiv7@gmail.com> | 2019-09-04 17:06:39 +0100 |
commit | 39d158a0142d8a9f38d7952a686cb53fa6542a5f (patch) | |
tree | fd75e008f591cd4db249ebb7b4ad57f2c560549b /src/sys/socket/addr.rs | |
parent | a4a465d25567f163f9552b977eb4d17435251d41 (diff) | |
download | nix-39d158a0142d8a9f38d7952a686cb53fa6542a5f.zip |
Fix length of abstract socket address
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>
Diffstat (limited to 'src/sys/socket/addr.rs')
-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 cbec71f7..1387c207 100644 --- a/src/sys/socket/addr.rs +++ b/src/sys/socket/addr.rs @@ -562,7 +562,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)) } } @@ -1300,7 +1300,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]); |