Use the correct return type for Windows' send()/recv() (Fix #12010)
authorTamar Christina <tamar@zhox.com>
Thu, 19 May 2016 19:48:53 +0000 (21:48 +0200)
committerTamar Christina <tamar@zhox.com>
Thu, 19 May 2016 19:50:18 +0000 (21:50 +0200)
commit1ee47c1bfa35c7be435adaec5c1fa9ec92cc776d
tree847fa95c9660bab533ede96135a43d799fadeb6d
parenta88bb1b1518389817583290acaebfd6454aa3cec
Use the correct return type for Windows' send()/recv() (Fix #12010)

Summary:
They return signed 32 bit ints on Windows, even on a 64 bit OS, rather than
Linux's 64 bit ssize_t. This means when recv() returned -1 to signal an error we
thought it was 4294967295. It was converted to an int, -1 and the buffer was
memcpy'd which caused a segfault. Other bad stuff happened with send()s.

See also note CSsize in System.Posix.Internals.

Add a test for #12010

Test Plan:
- GHC testsuite (T12010)
- http-conduit test (https://github.com/snoyberg/http-client/issues/191)

Reviewers: austin, hvr, bgamari, Phyx

Reviewed By: Phyx

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D2170

GHC Trac Issues: #12010
libraries/base/GHC/IO/FD.hs
libraries/base/System/Posix/Internals.hs
libraries/base/tests/IO/T12010/Makefile [new file with mode: 0644]
libraries/base/tests/IO/T12010/T12010.hsc [new file with mode: 0644]
libraries/base/tests/IO/T12010/T12010.stdout [new file with mode: 0644]
libraries/base/tests/IO/T12010/cbits/initWinSock.c [new file with mode: 0644]
libraries/base/tests/IO/T12010/test.T [new file with mode: 0644]