diff --git a/Network/Socket/Types.hsc b/Network/Socket/Types.hsc index 13fe3a8d..fd4d8c7b 100644 --- a/Network/Socket/Types.hsc +++ b/Network/Socket/Types.hsc @@ -1156,15 +1156,16 @@ unixPathMax = #const sizeof(((struct sockaddr_un *)NULL)->sun_path) -- | Write the given 'SockAddr' to the given memory location. pokeSockAddr :: Ptr a -> SockAddr -> IO () pokeSockAddr p sa@(SockAddrUnix path) = do - when (length path > unixPathMax) $ error + let pathC = map castCharToCChar path + len = length pathC + when (len >= unixPathMax) $ error $ "pokeSockAddr: path is too long in SockAddrUnix " <> show path - <> ", length " <> show (length path) <> ", unixPathMax " <> show unixPathMax + <> ", length " <> show len <> ", unixPathMax " <> show unixPathMax zeroMemory p $ fromIntegral $ sizeOfSockAddr sa # if defined(HAVE_STRUCT_SOCKADDR_SA_LEN) (#poke struct sockaddr_un, sun_len) p ((#const sizeof(struct sockaddr_un)) :: Word8) # endif (#poke struct sockaddr_un, sun_family) p ((#const AF_UNIX) :: CSaFamily) - let pathC = map castCharToCChar path -- the buffer is already filled with nulls. pokeArray ((#ptr struct sockaddr_un, sun_path) p) pathC pokeSockAddr p (SockAddrInet port addr) = do