Skip to content

Commit 8d9e69b

Browse files
Merge pull request #585 from kazu-yamamoto/sockaddr-unix-length-check
checking the length of ASCII string allowing trailing 0.
2 parents 2d5ebe6 + 33b45f8 commit 8d9e69b

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Network/Socket/Types.hsc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,15 +1156,16 @@ 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+
len = length pathC
1161+
when (len >= unixPathMax) $ error
11601162
$ "pokeSockAddr: path is too long in SockAddrUnix " <> show path
1161-
<> ", length " <> show (length path) <> ", unixPathMax " <> show unixPathMax
1163+
<> ", length " <> show len <> ", unixPathMax " <> show unixPathMax
11621164
zeroMemory p $ fromIntegral $ sizeOfSockAddr sa
11631165
# if defined(HAVE_STRUCT_SOCKADDR_SA_LEN)
11641166
(#poke struct sockaddr_un, sun_len) p ((#const sizeof(struct sockaddr_un)) :: Word8)
11651167
# endif
11661168
(#poke struct sockaddr_un, sun_family) p ((#const AF_UNIX) :: CSaFamily)
1167-
let pathC = map castCharToCChar path
11681169
-- the buffer is already filled with nulls.
11691170
pokeArray ((#ptr struct sockaddr_un, sun_path) p) pathC
11701171
pokeSockAddr p (SockAddrInet port addr) = do

0 commit comments

Comments
 (0)