Skip to content

Commit

Permalink
Merge pull request #2256 from stevvooe/cherry-pick-#2255
Browse files Browse the repository at this point in the history
[release/1.0] Return a better error message is unix socket path is too long.
  • Loading branch information
stevvooe committed Mar 30, 2018
2 parents 51cf56f + 34b7c1d commit 46a104a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cmd/containerd-shim/main_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ func serve(server *ttrpc.Server, path string) error {
l, err = net.FileListener(os.NewFile(3, "socket"))
path = "[inherited from parent]"
} else {
if len(path) > 106 {
return errors.Errorf("%q: unix socket path too long (> 106)", path)
}
l, err = net.Listen("unix", "\x00"+path)
}
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion linux/shim/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func newCommand(binary, daemonAddress string, debug bool, config shim.Config, so

func newSocket(address string) (*net.UnixListener, error) {
if len(address) > 106 {
return nil, errors.Errorf("%q: unix socket path too long (limit 106)", address)
return nil, errors.Errorf("%q: unix socket path too long (> 106)", address)
}
l, err := net.Listen("unix", "\x00"+address)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions sys/socket_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ import (
"os"
"path/filepath"

"github.com/pkg/errors"
"golang.org/x/sys/unix"
)

// CreateUnixSocket creates a unix socket and returns the listener
func CreateUnixSocket(path string) (net.Listener, error) {
// BSDs have a 104 limit
if len(path) > 104 {
return nil, errors.Errorf("%q: unix socket path too long (> 106)", path)
}
if err := os.MkdirAll(filepath.Dir(path), 0660); err != nil {
return nil, err
}
Expand Down

0 comments on commit 46a104a

Please sign in to comment.