Skip to content

Commit 1662466

Browse files
bors[bot]yshui
andauthored
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 <[email protected]> Co-authored-by: Yuxuan Shui <[email protected]>
2 parents 01f4d57 + 39d158a commit 1662466

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
4343
([#1107](https://github.com/nix-rust/nix/pull/1107))
4444

4545
### Fixed
46+
- Fix length of abstract socket addresses
47+
([#1120](https://github.com/nix-rust/nix/pull/1120))
48+
4649
### Removed
4750

4851
## [0.15.0] - 10 August 2019

src/sys/socket/addr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ impl UnixAddr {
560560
ret.sun_path.as_mut_ptr().offset(1) as *mut u8,
561561
path.len());
562562

563-
Ok(UnixAddr(ret, ret.sun_path.len()))
563+
Ok(UnixAddr(ret, path.len() + 1))
564564
}
565565
}
566566

@@ -1298,7 +1298,7 @@ mod tests {
12981298
let addr = UnixAddr::new_abstract(name.as_bytes()).unwrap();
12991299

13001300
let sun_path1 = addr.sun_path();
1301-
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];
1301+
let sun_path2 = [0u8, 110, 105, 120, 0, 97, 98, 115, 116, 114, 97, 99, 116, 0, 116, 101, 115, 116];
13021302
assert_eq!(sun_path1.len(), sun_path2.len());
13031303
for i in 0..sun_path1.len() {
13041304
assert_eq!(sun_path1[i], sun_path2[i]);

test/sys/test_socket.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub fn test_addr_equality_abstract() {
106106
assert_eq!(addr1, addr2);
107107
assert_eq!(calculate_hash(&addr1), calculate_hash(&addr2));
108108

109-
addr2.0.sun_path[18] = 127;
109+
addr2.0.sun_path[17] = 127;
110110
assert_ne!(addr1, addr2);
111111
assert_ne!(calculate_hash(&addr1), calculate_hash(&addr2));
112112
}
@@ -117,16 +117,13 @@ pub fn test_addr_equality_abstract() {
117117
pub fn test_abstract_uds_addr() {
118118
let empty = String::new();
119119
let addr = UnixAddr::new_abstract(empty.as_bytes()).unwrap();
120-
let sun_path = [0u8; 107];
120+
let sun_path: [u8; 0] = [];
121121
assert_eq!(addr.as_abstract(), Some(&sun_path[..]));
122122

123123
let name = String::from("nix\0abstract\0test");
124124
let addr = UnixAddr::new_abstract(name.as_bytes()).unwrap();
125125
let sun_path = [
126-
110u8, 105, 120, 0, 97, 98, 115, 116, 114, 97, 99, 116, 0, 116, 101, 115, 116, 0, 0, 0, 0,
127-
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,
128-
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,
129-
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,
126+
110u8, 105, 120, 0, 97, 98, 115, 116, 114, 97, 99, 116, 0, 116, 101, 115, 116
130127
];
131128
assert_eq!(addr.as_abstract(), Some(&sun_path[..]));
132129
assert_eq!(addr.path(), None);

0 commit comments

Comments
 (0)