diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-09-19 02:04:04 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-19 02:04:04 +0000 |
commit | 4f58c8c8e3fe76ea385953edf81491b9f0d3d001 (patch) | |
tree | 5990f70d34aa040ba3aed602f74e47e1e789f3c8 /test/sys/test_socket.rs | |
parent | 86fec803f987ba01437ff257b70e2daa2a271edb (diff) | |
parent | 8e963a093fe401552998d1cc358c67d71ffd5ad6 (diff) | |
download | nix-4f58c8c8e3fe76ea385953edf81491b9f0d3d001.zip |
Merge #1496
1496: Rework UnixAddr to fix soundness issues r=asomers a=coolreader18
Fixes #1494
I went with making `sun_path` always nul-terminated since that just seems to make things easier, since (at least according to linux man pages) `sockaddr_un`s returned by the kernel will always be nul-terminated.
Co-authored-by: Noa <33094578+coolreader18@users.noreply.github.com>
Diffstat (limited to 'test/sys/test_socket.rs')
-rw-r--r-- | test/sys/test_socket.rs | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/test/sys/test_socket.rs b/test/sys/test_socket.rs index 2b0bc831..6b998cb6 100644 --- a/test/sys/test_socket.rs +++ b/test/sys/test_socket.rs @@ -113,9 +113,9 @@ pub fn test_path_to_sock_addr() { let addr = UnixAddr::new(actual).unwrap(); let expect: &[c_char] = unsafe { - slice::from_raw_parts(path.as_bytes().as_ptr() as *const c_char, path.len()) + slice::from_raw_parts(path.as_ptr() as *const c_char, path.len()) }; - assert_eq!(&addr.0.sun_path[..8], expect); + assert_eq!(unsafe { &(*addr.as_ptr()).sun_path[..8] }, expect); assert_eq!(addr.path(), Some(actual)); } @@ -133,7 +133,7 @@ pub fn test_addr_equality_path() { let addr1 = UnixAddr::new(actual).unwrap(); let mut addr2 = addr1; - addr2.0.sun_path[10] = 127; + unsafe { (*addr2.as_mut_ptr()).sun_path[10] = 127 }; assert_eq!(addr1, addr2); assert_eq!(calculate_hash(&addr1), calculate_hash(&addr2)); @@ -157,7 +157,7 @@ pub fn test_addr_equality_abstract() { assert_eq!(addr1, addr2); assert_eq!(calculate_hash(&addr1), calculate_hash(&addr2)); - addr2.0.sun_path[17] = 127; + unsafe { (*addr2.as_mut_ptr()).sun_path[17] = 127 }; assert_ne!(addr1, addr2); assert_ne!(calculate_hash(&addr1), calculate_hash(&addr2)); } @@ -180,7 +180,7 @@ pub fn test_abstract_uds_addr() { assert_eq!(addr.path(), None); // Internally, name is null-prefixed (abstract namespace) - assert_eq!(addr.0.sun_path[0], 0); + assert_eq!(unsafe { (*addr.as_ptr()).sun_path[0] }, 0); } #[test] @@ -194,8 +194,7 @@ pub fn test_getsockname() { .expect("socket failed"); let sockaddr = SockAddr::new_unix(&sockname).unwrap(); bind(sock, &sockaddr).expect("bind failed"); - assert_eq!(sockaddr.to_string(), - getsockname(sock).expect("getsockname failed").to_string()); + assert_eq!(sockaddr, getsockname(sock).expect("getsockname failed")); } #[test] |