Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
alloc_sockaddr: Unix domain sockets: use provided address length #987
macOS (apparently) does not null-terminate Unix domain socket paths returned by
The following code reproduces the problem on my macOS system, with
let () = let socket_path = "foobar" in let rec repeat = function | 0 -> () | n -> let fd = Unix.(socket PF_UNIX SOCK_STREAM 0) in Unix.(bind fd (ADDR_UNIX socket_path)); let actual_path = match Unix.getsockname fd with | Unix.ADDR_UNIX path -> path | _ -> assert false in Unix.close fd; Unix.unlink socket_path; if actual_path <> socket_path then begin prerr_endline actual_path; String.iter (fun c -> Printf.eprintf "%02X " (Char.code c)) actual_path; prerr_newline (); exit 1 end; repeat (n - 1) in repeat 2 (* ocamlfind opt -linkpkg -package unix repro.ml *)
Running it produces outputs such as
I looked in
added a commit
this pull request
Dec 25, 2016
You put the changelog entry in the section dedicated to the next minor release, which corresponds to the 4.04 branch, not trunk. Assuming that this bugfix is not urgent (this has been wrong for a long time so it can probably wait for the next major release), I think that trunk would be the better section. Also it would be nice if the changelog could explicitly mention that this was a bug affecting MacOS specifically -- so that people experiencing MacOS-specific issues with older versions can find it.
@aantron adding tests to the current testsuite is indeed non trivial. However the code you show really seems worth being added to the testsuite, IMO. Would you accept to give ocamltest a try and see whether an ocamltest test could be added? If not, I'd be intereesting in knowing what, according to you, is missing in ocamltest to support the test you would like to write. #681
@gasche Moved it. Not sure which section it belongs in: Other libraries, or Bug fixes? There seems to be a bug fix to Unix in Other libraries, but it is breaking. Since this is not a major feature or breaking, I put it in Bug fixes for now.
For thoroughness, I'm mentioning the accidents that prevented this from being a bug on Linux.
@shindere I looked at the current test setup and ocamltest, but I am not able to readily find an example of an existing test that causes a side effect in the filesystem (relative to just ordinary compilation of the test), nor is there documentation in HACKING.adoc about where/how this is allowed. I'm reluctant to write a test that messes with an unfamiliar test environment in this way. Also, it has to be skipped on Windows, would I just add
A bit of a tangent, but testing in Travis on macOS would make the hypothetical test for this PR more immediately relevant.
As far as I am concerned, this is good to merge. I don't have a strong opinion on whether it makes sense to delay the fix until we have an