libcontainer: handle error cases

Handle err return value of fmt.Scanf, os.Pipe and unix.ParseUnixRights.

Found with honnef.co/go/tools/cmd/staticcheck

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
This commit is contained in:
Tobias Klauser 2017-07-28 13:56:33 +02:00
parent 5951cf5f36
commit 24a4273cf9
3 changed files with 18 additions and 0 deletions

View File

@ -596,6 +596,9 @@ func (c *linuxContainer) checkCriuVersion(minVersion string) error {
_, err := fmt.Sscanf(minVersion, "%d.%d.%d\n", &x, &y, &z) // 1.5.2
if err != nil {
_, err = fmt.Sscanf(minVersion, "Version: %d.%d\n", &x, &y) // 1.6
if err != nil {
return fmt.Errorf("Unable to parse the CRIU min version: %s", minVersion)
}
}
versionReq = x*10000 + y*100 + z
@ -1295,6 +1298,9 @@ func (c *linuxContainer) criuNotifications(resp *criurpc.CriuResp, process *Proc
return err
}
fds, err := unix.ParseUnixRights(&scm[0])
if err != nil {
return err
}
master := os.NewFile(uintptr(fds[0]), "orphan-pts-master")
defer master.Close()

View File

@ -807,7 +807,13 @@ func TestPassExtraFiles(t *testing.T) {
var stdout bytes.Buffer
pipeout1, pipein1, err := os.Pipe()
if err != nil {
t.Fatal(err)
}
pipeout2, pipein2, err := os.Pipe()
if err != nil {
t.Fatal(err)
}
process := libcontainer.Process{
Cwd: "/",
Args: []string{"sh", "-c", "cd /proc/$$/fd; echo -n *; echo -n 1 >3; echo -n 2 >4"},

View File

@ -431,7 +431,13 @@ func TestExecinPassExtraFiles(t *testing.T) {
var stdout bytes.Buffer
pipeout1, pipein1, err := os.Pipe()
if err != nil {
t.Fatal(err)
}
pipeout2, pipein2, err := os.Pipe()
if err != nil {
t.Fatal(err)
}
inprocess := &libcontainer.Process{
Cwd: "/",
Args: []string{"sh", "-c", "cd /proc/$$/fd; echo -n *; echo -n 1 >3; echo -n 2 >4"},