Skip to content

Commit 34b7c1d

Browse files
mlaventurestevvooe
authored andcommitted
Return a better error message is unix socket path is too long.
Signed-off-by: Kenfe-Mickael Laventure <[email protected]> (cherry picked from commit 3c3a676) Signed-off-by: Stephen J Day <[email protected]>
1 parent 51cf56f commit 34b7c1d

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
@@ -146,6 +146,9 @@ func serve(server *ttrpc.Server, path string) error {
146146
l, err = net.FileListener(os.NewFile(3, "socket"))
147147
path = "[inherited from parent]"
148148
} else {
149+
if len(path) > 106 {
150+
return errors.Errorf("%q: unix socket path too long (> 106)", path)
151+
}
149152
l, err = net.Listen("unix", "\x00"+path)
150153
}
151154
if err != nil {

linux/shim/client/client.go

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

127127
func newSocket(address string) (*net.UnixListener, error) {
128128
if len(address) > 106 {
129-
return nil, errors.Errorf("%q: unix socket path too long (limit 106)", address)
129+
return nil, errors.Errorf("%q: unix socket path too long (> 106)", address)
130130
}
131131
l, err := net.Listen("unix", "\x00"+address)
132132
if err != nil {

sys/socket_unix.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@ import (
77
"os"
88
"path/filepath"
99

10+
"github.com/pkg/errors"
1011
"golang.org/x/sys/unix"
1112
)
1213

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

0 commit comments

Comments
 (0)