Skip to content

Commit 3c3a676

Browse files
committed
Return a better error message is unix socket path is too long.
Signed-off-by: Kenfe-Mickael Laventure <[email protected]>
1 parent 606be14 commit 3c3a676

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

cmd/containerd-shim/main_unix.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ func serve(server *ttrpc.Server, path string) error {
162162
l, err = net.FileListener(os.NewFile(3, "socket"))
163163
path = "[inherited from parent]"
164164
} else {
165+
if len(path) > 106 {
166+
return errors.Errorf("%q: unix socket path too long (> 106)", path)
167+
}
165168
l, err = net.Listen("unix", "\x00"+path)
166169
}
167170
if err != nil {

linux/shim/client/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func newCommand(binary, daemonAddress string, debug bool, config shim.Config, so
145145

146146
func newSocket(address string) (*net.UnixListener, error) {
147147
if len(address) > 106 {
148-
return nil, errors.Errorf("%q: unix socket path too long (limit 106)", address)
148+
return nil, errors.Errorf("%q: unix socket path too long (> 106)", address)
149149
}
150150
l, err := net.Listen("unix", "\x00"+address)
151151
if err != nil {

sys/socket_unix.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,16 @@ import (
2323
"os"
2424
"path/filepath"
2525

26+
"github.com/pkg/errors"
2627
"golang.org/x/sys/unix"
2728
)
2829

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

0 commit comments

Comments
 (0)