From 323c91fad80c2cf02acdd42ed8a009153ed01b49 Mon Sep 17 00:00:00 2001 From: Joseph Lee Date: Fri, 10 Jan 2025 10:40:29 +0900 Subject: [PATCH] fix: use null-terminator if incorrect length --- efi/efivario/context_windows.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/efi/efivario/context_windows.go b/efi/efivario/context_windows.go index 93807c3..c7db299 100644 --- a/efi/efivario/context_windows.go +++ b/efi/efivario/context_windows.go @@ -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