Merge pull request #1704 from giuseppe/attach-cuid-too-long

attach: fix attach when cuid is too long
This commit is contained in:
OpenShift Merge Robot 2018-10-30 14:22:01 -07:00 committed by GitHub
commit ee513cca86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 3 deletions

View File

@ -5,6 +5,7 @@ import (
"github.com/containers/libpod/pkg/rootless" "github.com/containers/libpod/pkg/rootless"
"github.com/containers/libpod/pkg/util" "github.com/containers/libpod/pkg/util"
"github.com/containers/storage" "github.com/containers/storage"
"github.com/pkg/errors"
"github.com/urfave/cli" "github.com/urfave/cli"
) )
@ -42,6 +43,9 @@ func GetRuntimeWithStorageOpts(c *cli.Context, storageOpts *storage.StoreOptions
if c.GlobalIsSet("runroot") { if c.GlobalIsSet("runroot") {
storageOpts.RunRoot = c.GlobalString("runroot") storageOpts.RunRoot = c.GlobalString("runroot")
} }
if len(storageOpts.RunRoot) > 50 {
return nil, errors.New("the specified runroot is longer than 50 characters")
}
if c.GlobalIsSet("storage-driver") { if c.GlobalIsSet("storage-driver") {
storageOpts.GraphDriverName = c.GlobalString("storage-driver") storageOpts.GraphDriverName = c.GlobalString("storage-driver")
} }

View File

@ -16,6 +16,10 @@ import (
"k8s.io/client-go/tools/remotecommand" "k8s.io/client-go/tools/remotecommand"
) )
//#include <sys/un.h>
// extern int unix_path_length(){struct sockaddr_un addr; return sizeof(addr.sun_path) - 1;}
import "C"
/* Sync with stdpipe_t in conmon.c */ /* Sync with stdpipe_t in conmon.c */
const ( const (
AttachPipeStdin = 1 AttachPipeStdin = 1
@ -81,11 +85,19 @@ func (c *Container) attachContainerSocket(resize <-chan remotecommand.TerminalSi
logrus.Warnf("Failed to write to control file to resize terminal: %v", err) logrus.Warnf("Failed to write to control file to resize terminal: %v", err)
} }
}) })
logrus.Debug("connecting to socket ", c.AttachSocketPath())
conn, err := net.DialUnix("unixpacket", nil, &net.UnixAddr{Name: c.AttachSocketPath(), Net: "unixpacket"}) socketPath := c.AttachSocketPath()
maxUnixLength := int(C.unix_path_length())
if maxUnixLength < len(socketPath) {
socketPath = socketPath[0:maxUnixLength]
}
logrus.Debug("connecting to socket ", socketPath)
conn, err := net.DialUnix("unixpacket", nil, &net.UnixAddr{Name: socketPath, Net: "unixpacket"})
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to connect to container's attach socket: %v", c.AttachSocketPath()) return errors.Wrapf(err, "failed to connect to container's attach socket: %v", socketPath)
} }
defer conn.Close() defer conn.Close()