Ticket #1 (closed defect: fixed)

Opened 6 years ago

Last modified 5 years ago

unpackFamily on Windows fails match

Reported by: igloo Owned by: bos
Priority: major Milestone:
Component: network Version:
Keywords: Cc:

Description

Initially reported here: http://hackage.haskell.org/trac/ghc/ticket/2250


In the HostEntry? returned by Network.BSD.getHostByName, evaluating the hostFamily field causes the following error, which is pointing at the unpackFamily function:

*** Exception: Network/Socket.hsc:(1711,17)-(1777,13): Non-exhaustive patterns in case

This occurs with 6.8.2 and 6.9.20080323 i386. The machine is running Windows Server 2008 x64.


I modified Network/BSD.hs to trace out the h_addrtype variable in Storable HostEntry's peek, and it had the value 0x40002. The corresponding variable in the C struct should be a short, but is inferred to be CInt in the Haskell source, probably thanks to unpackFamily having type CInt -> Family. Due to that, it reads the family as an int, consuming the following length field as well.

I hacked past this by giving the peek of h_addrtype an annotation of ":: IO CShort" and adding a fromIntegral at the call to unpackFamily to convert it to the CInt that the unpackFamily function expects.


Great stuff, thanks! It looks like it should be CSaFamily rather than CInt. Likewise packFamily, and I expect the whole library could do with an audit.


I can reproduce the exact bug on the following combinations:

- GHC 6.8.2, x86, Windows XP - GHC 6.8.3, x86, Windows XP - GHC 6.8.2, x86, Windows Vista - GHC 6.8.3, x86, Windows Vista - GHC 6.8.2, x64, Windows Vista - GHC 6.8.3, x64, Windows Vista

Change History

Changed 6 years ago by igloo

  • owner somebody deleted

Changed 6 years ago by igloo

Testcase:

module Main where
import Network.BSD
main = getHostByName "zao.se" >>= print

Changed 5 years ago by anonymous

  • component changed from component1 to network

Changed 5 years ago by tibbe

I have limited access to Windows machines. If someone could come up with a rough patch that addresses this bug I'd be happy to review it.

Changed 5 years ago by bos

  • owner set to bos

I'll take a look at this.

Changed 5 years ago by bos

  • status changed from new to closed
  • resolution set to fixed

Fix pushed to darcs repo.

Changed 5 years ago by tibbe

Thanks for the fix. I'll make one more release before the next release of the Haskell Platform. I'll wait and see if there are any other bugs that need fixing first.

Note: See TracTickets for help on using tickets.