Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

UnixSocket handled strangely by connectTo and accept #10

Open
bmillwood opened this Issue · 1 comment

2 participants

@bmillwood

If connectTo is used with a UnixSocket, it completely ignores the hostname argument. Which is good because there's nothing sensible to put in there, but bad because you have to fill it with a useless value (e.g. undefined), and this isn't at all mentioned in the docs.

When Network.accept is used with a socket from Network.listenOn with a UnixSocket argument, the host is filled with garbage and the port is always 65535. This is highly worrying:

module NetworkTest where

import Control.Exception

import Network
import System.IO

path :: String
path = "/tmp/networktest.sock"

server :: IO ()
server = bracket (listenOn (UnixSocket path)) close $ \s ->
  bracket (accept s) (\(h,_,_) -> hClose h) $ \(h,them,themport) ->
    putStrLn $ "Connection from: " ++ show (them,themport)

client :: IO ()
client = bracket (connectTo undefined (UnixSocket path)) hClose $ \h ->
  return ()
ghci> forkIO server
ThreadId 173
ghci> client
Connection from: ("rkov-chain-0.0.3.1ry-0\228\US\DC2\t\SO",65535)

I have no idea what is being printed here but it doesn't look safe.

@tibbe
Owner

I'll have a look. The API for connectTo is quite odd indeed. Perhaps we should change it to something more sane in the next major release.

@tibbe tibbe was assigned
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.