Skip to content

Commit

Permalink
net: Improve error when unix socket path length is over 104
Browse files Browse the repository at this point in the history
Path used for unix socket client/server endpoints have to be less than
104. When this is not the case, `bind: invalid argument` is returned.
This commit checks the path length before calling `DialUnix` in order to
provide an easier to understand error message.

Signed-off-by: Christophe Fergeau <[email protected]>
  • Loading branch information
cfergeau committed Sep 23, 2024
1 parent 303dbf5 commit 8cdea09
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/vf/virtionet.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ func localUnixSocketPath(dir string) (string, error) {
}

func (dev *VirtioNet) connectUnixPath() error {
// path for unixgram sockets must be less than 104 bytes on macOS
const maxUnixgramPathLen = 104

remoteAddr := net.UnixAddr{
Name: dev.UnixSocketPath,
Net: "unixgram",
Expand All @@ -40,7 +43,10 @@ func (dev *VirtioNet) connectUnixPath() error {
if err != nil {
return err
}
// FIXME: need to remove localSocketPath at process exit
if len(localSocketPath) >= maxUnixgramPathLen {
return fmt.Errorf("unixgram path '%s' is too long: %d >= %d bytes", localSocketPath, len(localSocketPath), maxUnixgramPathLen)
}
// FIXME: need to remove localSocketPath at process exit
localAddr := net.UnixAddr{
Name: localSocketPath,
Net: "unixgram",
Expand Down

0 comments on commit 8cdea09

Please sign in to comment.