cmd/makemac: check slice length in isFileSystemReadOnly before access

This is a followup to CL 181217 to address a minor code review comment.
Check the slice length before access, to prevent a possible panic on
unexpected input.

Also improve error string to not end with punctuation, per style guide
entry at golang.org/s/style#error-strings.

Change-Id: I220f6744396740b0e7f92705367be56c83ee23da
Reviewed-on: https://go-review.googlesource.com/c/build/+/182337
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alexander Rakoczy <alex@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
This commit is contained in:
Dmitri Shuralyov 2019-06-13 18:28:59 -04:00
Родитель 2f0768f8d8
Коммит c7084d3a2d
1 изменённых файлов: 4 добавлений и 1 удалений

Просмотреть файл

@ -501,7 +501,7 @@ func findBaseDisk(ctx context.Context, minor int) (string, error) {
}
vm := ret.VirtualMachines[0]
if len(vm.Layout.Snapshot) < 1 {
return "", fmt.Errorf("VM %s does not have any snapshots. Needs at least one.", vmName)
return "", fmt.Errorf("VM %s does not have any snapshots; needs at least one", vmName)
}
ss := vm.Layout.Snapshot[len(vm.Layout.Snapshot)-1] // most recent snapshot is last in list
@ -860,6 +860,9 @@ func isFileSystemReadOnly() bool {
bs := bufio.NewScanner(f)
for bs.Scan() {
f := strings.Fields(bs.Text())
if len(f) < 4 {
continue
}
mountPoint, state := f[1], f[3]
if mountPoint == "/" {
return strings.HasPrefix(state, "ro,")