From 39d158a0142d8a9f38d7952a686cb53fa6542a5f Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Wed, 4 Sep 2019 13:32:26 +0100 Subject: 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 --- src/sys/socket/addr.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/sys/socket') 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]); -- cgit v1.2.3