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

Fix path validation for abstract unix socket. #1605

Closed
wants to merge 1 commit into from

Conversation

RealXuChe
Copy link

The validation of abstract unix socket is wrong, and I fixed it.
Look at the original validation code:

match (bytes.get(0), bytes.len().cmp(&sockaddr.sun_path.len())) {
    // Abstract paths don't need a null terminator
    (Some(&0), Ordering::Greater) => {
        return Err(io::Error::new(
            io::ErrorKind::InvalidInput,
            "path must be no longer than libc::sockaddr_un.sun_path",
        ));
    }
    (_, Ordering::Greater) | (_, Ordering::Equal) => {
        return Err(io::Error::new(
            io::ErrorKind::InvalidInput,
            "path must be shorter than libc::sockaddr_un.sun_path",
        ));
    }
    _ => {}
}

Abstract paths don't need a null terminator, so it's valid when it's no longer than the libc::sockaddr_un.sun_path. However, when the length of an abstract path equals to sun_path, (Some(&0), Ordering::Equal) will match on the second arm and will return an error.

I added the branch (Some(&0), _) => {} to accept such case.

Copy link
Collaborator

@Thomasdezeeuw Thomasdezeeuw left a comment

Choose a reason for hiding this comment

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

Can you add a test for this?

Also this is going to be replaced pretty soon: #1527.

@Thomasdezeeuw
Copy link
Collaborator

Closing in favour of #1749, which removes this code.

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.

2 participants