Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checking the length of ASCII string allowing trailing 0. #585

Merged

Conversation

kazu-yamamoto
Copy link
Collaborator

@nh2 This should fix #584

@@ -1156,15 +1156,15 @@ 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
when (length pathC >= unixPathMax) $ error
$ "pokeSockAddr: path is too long in SockAddrUnix " <> show path
<> ", length " <> show (length path) <> ", unixPathMax " <> show unixPathMax
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be good to change the error message to show (length pathC); currently it's equivalent since done with map, but maybe in the future we lift the constraint in the future that the path must not contain unicode chars (which is a pretty weird contraint because it should prevent anybody who uses non-ASCII chars in their home directory to place sockets there).

Otherwise, looks good!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Please check it again.

@kazu-yamamoto kazu-yamamoto merged commit 8d9e69b into haskell:master Aug 27, 2024
13 of 14 checks passed
@kazu-yamamoto kazu-yamamoto deleted the sockaddr-unix-length-check branch August 27, 2024 07:32
@kazu-yamamoto
Copy link
Collaborator Author

Merging without the second review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pokeSockAddr check ignores multi-char Unicode bytes and forgets about NULL terminator
2 participants