Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing unix socket on 2.8 #400

Merged
merged 4 commits into from
Apr 24, 2019
Merged

Conversation

kazu-yamamoto
Copy link
Collaborator

eborden and others added 4 commits April 23, 2019 16:02
This is a simple end-to-end test for abstract sockets. It is possible to
implement tests for address bounds, but those require system specific
information and would require exports from `Network.Socket.Types`. As
such a simple end-to-end tests provides a good balance of coverage.

Simple bounds checking may look like:

```
it "can end-to-end with long abstract socket names" $ do
 when isUnixDomainSocketAvailable $ do
     let
	 abstractAddress =
	     toEnum 0:
	     "/haskell/network/long-abstract-" ++
	     replicate 76 'a'
	 clientAct sock = send sock testMsg
	 server (sock, addr) = do
	   recv sock 1024 `shouldReturn` testMsg
	   addr `shouldBe` (SockAddrUnix "")
     unixTestWith abstractAddress (const $ pure ()) clientAct server
it "fails with too long abstract socket names" $ do
 when isUnixDomainSocketAvailable $ do
     let
	 abstractAddress =
	     toEnum 0:
	     "/haskell/network/long-abstract-" ++
	     replicate 77 'a'
	 clientAct _ = pure ()
	 server _ = pure ()
     unixTestWith abstractAddress (const $ pure ()) clientAct server
	 `shouldThrow` anyErrorCall
```

However this hard codes the bounds and would fail when system specific
configuration differs.
There are two cases where pokeSockAddr can write past the
end of the sockaddr_un structure and corrupt the heap:
- when processing a very large Unix socket path
- when processing the address of a Linux abstract Unix socket,
  where (2 + length path) bytes are allocated but sizeof(sockadr_un)
  are written.

The fix is backported from version 3.0.0.0.
Copy link
Collaborator

@eborden eborden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for jumping on this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants