Fix errors found in coverity scan

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
Daniel J Walsh 2020-04-30 16:25:45 -04:00
parent 226e0da6fe
commit 8173e83054
No known key found for this signature in database
GPG key ID: A2DF901DABE2C028
4 changed files with 20 additions and 16 deletions

View file

@ -661,7 +661,7 @@ func (c *Container) generateInspectContainerHostConfig(ctrSpec *spec.Spec, named
if ns.Path != "" {
networkMode = fmt.Sprintf("ns:%s", ns.Path)
} else {
networkMode = "none"
networkMode = "private"
}
break
}
@ -743,22 +743,23 @@ func (c *Container) generateInspectContainerHostConfig(ctrSpec *spec.Spec, named
ipcMode := ""
if c.config.IPCNsCtr != "" {
ipcMode = fmt.Sprintf("container:%s", c.config.IPCNsCtr)
} else {
} else if ctrSpec.Linux != nil {
// Locate the spec's IPC namespace.
// If there is none, it's ipc=host.
// If there is one and it has a path, it's "ns:".
// If no path, it's default - the empty string.
foundIPCNS := false
for _, ns := range ctrSpec.Linux.Namespaces {
if ns.Type == spec.IPCNamespace {
foundIPCNS = true
if ns.Path != "" {
ipcMode = fmt.Sprintf("ns:%s", ns.Path)
} else {
ipcMode = "private"
}
break
}
}
if !foundIPCNS {
if ipcMode == "" {
ipcMode = "host"
}
}
@ -781,22 +782,22 @@ func (c *Container) generateInspectContainerHostConfig(ctrSpec *spec.Spec, named
pidMode := ""
if c.config.PIDNsCtr != "" {
pidMode = fmt.Sprintf("container:%s", c.config.PIDNsCtr)
} else {
} else if ctrSpec.Linux != nil {
// Locate the spec's PID namespace.
// If there is none, it's pid=host.
// If there is one and it has a path, it's "ns:".
// If there is no path, it's default - the empty string.
foundPIDNS := false
for _, ns := range ctrSpec.Linux.Namespaces {
if ns.Type == spec.PIDNamespace {
foundPIDNS = true
if ns.Path != "" {
pidMode = fmt.Sprintf("ns:%s", ns.Path)
} else {
pidMode = "private"
}
break
}
}
if !foundPIDNS {
if pidMode == "" {
pidMode = "host"
}
}
@ -806,22 +807,23 @@ func (c *Container) generateInspectContainerHostConfig(ctrSpec *spec.Spec, named
utsMode := ""
if c.config.UTSNsCtr != "" {
utsMode = fmt.Sprintf("container:%s", c.config.UTSNsCtr)
} else {
} else if ctrSpec.Linux != nil {
// Locate the spec's UTS namespace.
// If there is none, it's uts=host.
// If there is one and it has a path, it's "ns:".
// If there is no path, it's default - the empty string.
foundUTSNS := false
for _, ns := range ctrSpec.Linux.Namespaces {
if ns.Type == spec.UTSNamespace {
foundUTSNS = true
if ns.Path != "" {
utsMode = fmt.Sprintf("ns:%s", ns.Path)
} else {
utsMode = "private"
}
break
}
}
if !foundUTSNS {
if utsMode == "" {
utsMode = "host"
}
}
@ -831,11 +833,12 @@ func (c *Container) generateInspectContainerHostConfig(ctrSpec *spec.Spec, named
usernsMode := ""
if c.config.UserNsCtr != "" {
usernsMode = fmt.Sprintf("container:%s", c.config.UserNsCtr)
} else {
} else if ctrSpec.Linux != nil {
// Locate the spec's user namespace.
// If there is none, it's default - the empty string.
// If there is one, it's "private" if no path, or "ns:" if
// there's a path.
for _, ns := range ctrSpec.Linux.Namespaces {
if ns.Type == spec.UserNamespace {
if ns.Path != "" {

View file

@ -731,7 +731,7 @@ func (r *ConmonOCIRuntime) ExecContainer(c *Container, sessionID string, options
args = append(args, "-t")
}
if options.Streams.AttachInput {
if options.Streams != nil && options.Streams.AttachInput {
args = append(args, "-i")
}

View file

@ -236,7 +236,7 @@ func (r *Runtime) removePod(ctx context.Context, p *Pod, removeCtrs, force bool)
}
if err := r.removeContainer(ctx, ctr, force, false, true); err != nil {
if removalErr != nil {
if removalErr == nil {
removalErr = err
} else {
logrus.Errorf("Error removing container %s from pod %s: %v", ctr.ID(), p.ID(), err)

View file

@ -108,6 +108,7 @@ func ProcessOptions(options []string, isTmpfs bool, sourcePath string) ([]string
if foundZ {
return nil, errors.Wrapf(ErrDupeMntOption, "only one of 'z' and 'Z' can be used")
}
foundZ = true
default:
return nil, errors.Wrapf(ErrBadMntOption, "unknown mount option %q", opt)
}