Skip to content
This repository has been archived by the owner on Sep 22, 2020. It is now read-only.

tcmu: check error before checking the result of length #420

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions internal/tcmu/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ func (h *torusHandler) handleWrite(cmd *tcmu.SCSICmd) (tcmu.SCSIResponse, error)
cmd.Buf = make([]byte, length)
}
n, err := cmd.Read(cmd.Buf[:int(length)])
if n < length {
clog.Error("write/read failed: unable to copy enough")
return cmd.MediumError(), nil
}
if err != nil {
clog.Errorf("write/read failed: error: %v", err)
return cmd.MediumError(), nil
}
if n < length {
clog.Error("write/read failed: unable to copy enough")
return cmd.MediumError(), nil
}
n, err = h.file.WriteAt(cmd.Buf[:length], int64(offset))
if n < length {
clog.Error("write/write failed: unable to copy enough")
Expand Down