-
Notifications
You must be signed in to change notification settings - Fork 188
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
Incorrect handling of address
argument in recvfrom()
#539
Comments
@Philonous As you think, |
@Philonous Gentle ping. |
I'm working on it. This isn't as obvious as I first thought.
However, there's another problem: network/Network/Socket/Types.hsc Line 1192 in 09f30fa
is incorrect:
As far as I can see, the interface
|
Why don't you use |
Can't we use |
We already have
|
Let's introduce a breaking change: peekSocketAddress :: Ptr sa -> Int -> IO sa And let's release it with a new major version. |
I've been working on this, but I've been stuck on network/Network/Socket/Buffer.hsc Line 125 in 26e9d3c
I think the idea here is that for connected sockets, This assumes that Next I tried to figure out if I think this is brittle. A slightly better idea (in my opinion) might be to store the address family in the But I think the morally correct approach would be to change
to
and remove the call to It would remove the possibility of failure and more closely resemble the the underlying API. |
I would suggest to keep |
We started a project for version 3.2. |
Context:
recvfrom()
stores the source address of a received package in thesockaddr
structure pointed to by theaddress
pointer and the length of the address is stored in the memory pointed to by theaddress_len
argument.Problem description:
However, not all protocol provide source addresses, e.g. AF_UNIX does not.
In this case, the contents of the
address
parameter is "unspecified" [1] and should not be inspected. I have not found it in the specification, but in practice I have observed that at least on Linuxaddress_len
is set to 0recvBufFrom
does not checkaddress_len
at all and instead tries to parse the contents ofaddress
directly [2]. This leads to an error because it interprets the zeroed memory asAF_UNSPEC
which is not supported. The error is ignored andgetPeerName
is called, which also fails.The solution is to
peek ptr_len
and check if it is0
, and if so to return an "unset" address. I'm not sure how best to represent such an address, perhapsSockAddrUnix []
would do the trick?Compare also how Rust handles the situation [3]
I have included a minimal code example that reproduced the problem [4]
network/Network/Socket/Buffer.hsc
Lines 114 to 126 in 26e9d3c
The text was updated successfully, but these errors were encountered: