Skip to content

Commit

Permalink
fix: use null-terminator if incorrect length
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-zeronsoftn committed Jan 10, 2025
1 parent 55b0c6b commit 323c91f
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions efi/efivario/context_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,24 @@ func (e *bufferVarEntry) ReadFrom(r io.Reader) (n int64, err error) {
return
}

e.Name = make([]byte, e.Length-20)
if _, err = io.ReadFull(fr, e.Name); err != nil {
return
if e.Length < 20 {
var nameBuffer []byte
for {
var u16char [2]byte
if err = fr.ReadFields(u16char[:]); err != nil {
return
}
nameBuffer = append(nameBuffer, u16char[0], u16char[1])
if u16char[0] == 0 && u16char[1] == 0 {
break
}
}
e.Name = nameBuffer
} else {
e.Name = make([]byte, e.Length-20)
if _, err = io.ReadFull(fr, e.Name); err != nil {
return
}
}

return
Expand Down

0 comments on commit 323c91f

Please sign in to comment.