Skip to content

Commit 412dd0d

Browse files
committed
checking the length of ASCII string allowing trailing 0.
1 parent 2d5ebe6 commit 412dd0d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Network/Socket/Types.hsc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,15 +1156,15 @@ unixPathMax = #const sizeof(((struct sockaddr_un *)NULL)->sun_path)
11561156
-- | Write the given 'SockAddr' to the given memory location.
11571157
pokeSockAddr :: Ptr a -> SockAddr -> IO ()
11581158
pokeSockAddr p sa@(SockAddrUnix path) = do
1159-
when (length path > unixPathMax) $ error
1159+
let pathC = map castCharToCChar path
1160+
when (length pathC >= unixPathMax) $ error
11601161
$ "pokeSockAddr: path is too long in SockAddrUnix " <> show path
11611162
<> ", length " <> show (length path) <> ", unixPathMax " <> show unixPathMax
11621163
zeroMemory p $ fromIntegral $ sizeOfSockAddr sa
11631164
# if defined(HAVE_STRUCT_SOCKADDR_SA_LEN)
11641165
(#poke struct sockaddr_un, sun_len) p ((#const sizeof(struct sockaddr_un)) :: Word8)
11651166
# endif
11661167
(#poke struct sockaddr_un, sun_family) p ((#const AF_UNIX) :: CSaFamily)
1167-
let pathC = map castCharToCChar path
11681168
-- the buffer is already filled with nulls.
11691169
pokeArray ((#ptr struct sockaddr_un, sun_path) p) pathC
11701170
pokeSockAddr p (SockAddrInet port addr) = do

0 commit comments

Comments
 (0)