From 206fb152261f10c9b55543103526e13d25377169 Mon Sep 17 00:00:00 2001 From: Marcus Comstedt Date: Mon, 22 Aug 2022 11:05:46 +0200 Subject: [PATCH] Fix bitsize of cmsgHdrLen and msgCtrlLen on Posix These fields are size_t, so using CInt on LP64 only accesses 32 bits of the total 64. This is especially noticable on big endian, where the lower 32 bits of the number are written to the upper 32 bits of the field. --- Network/Socket/Posix/CmsgHdr.hsc | 6 +++--- Network/Socket/Posix/MsgHdr.hsc | 2 +- cbits/cmsg.c | 4 ++-- include/HsNet.h | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Network/Socket/Posix/CmsgHdr.hsc b/Network/Socket/Posix/CmsgHdr.hsc index f122ea3b..6b47d59c 100644 --- a/Network/Socket/Posix/CmsgHdr.hsc +++ b/Network/Socket/Posix/CmsgHdr.hsc @@ -22,7 +22,7 @@ import Network.Socket.Posix.MsgHdr import Network.Socket.Types data CmsgHdr = CmsgHdr { - cmsgHdrLen :: !CInt + cmsgHdrLen :: !CSize , cmsgHdrLevel :: !CInt , cmsgHdrType :: !CInt } deriving (Eq, Show) @@ -96,7 +96,7 @@ foreign import ccall unsafe "cmsg_data" c_cmsg_data :: Ptr CmsgHdr -> IO (Ptr Word8) foreign import ccall unsafe "cmsg_space" - c_cmsg_space :: CInt -> CInt + c_cmsg_space :: CSize -> CSize foreign import ccall unsafe "cmsg_len" - c_cmsg_len :: CInt -> CInt + c_cmsg_len :: CSize -> CSize diff --git a/Network/Socket/Posix/MsgHdr.hsc b/Network/Socket/Posix/MsgHdr.hsc index 40b1c7a5..84a7651c 100644 --- a/Network/Socket/Posix/MsgHdr.hsc +++ b/Network/Socket/Posix/MsgHdr.hsc @@ -19,7 +19,7 @@ data MsgHdr sa = MsgHdr , msgIov :: !(Ptr IOVec) , msgIovLen :: !CSize , msgCtrl :: !(Ptr Word8) - , msgCtrlLen :: !CInt + , msgCtrlLen :: !CSize , msgFlags :: !CInt } diff --git a/cbits/cmsg.c b/cbits/cmsg.c index c532f5ad..105dd197 100644 --- a/cbits/cmsg.c +++ b/cbits/cmsg.c @@ -87,11 +87,11 @@ unsigned char *cmsg_data(struct cmsghdr *cmsg) { return (CMSG_DATA(cmsg)); } -int cmsg_space(int l) { +size_t cmsg_space(size_t l) { return (CMSG_SPACE(l)); } -int cmsg_len(int l) { +size_t cmsg_len(size_t l) { return (CMSG_LEN(l)); } #endif /* _WIN32 */ diff --git a/include/HsNet.h b/include/HsNet.h index ba016148..b623a97e 100644 --- a/include/HsNet.h +++ b/include/HsNet.h @@ -126,11 +126,11 @@ cmsg_nxthdr(struct msghdr *mhdr, struct cmsghdr *cmsg); extern unsigned char * cmsg_data(struct cmsghdr *cmsg); -extern int -cmsg_space(int l); +extern size_t +cmsg_space(size_t l); -extern int -cmsg_len(int l); +extern size_t +cmsg_len(size_t l); #endif /* _WIN32 */ INLINE int