From d9a4afc5d342f128136c16123fab6ae7d5b8b467 Mon Sep 17 00:00:00 2001 From: Philipp Deppenwiese Date: Thu, 12 Jan 2023 16:13:33 +0100 Subject: [PATCH 1/2] parse entire struct Signed-off-by: Philipp Deppenwiese --- pkg/intel/metadata/common/bgheader/bgheader.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/pkg/intel/metadata/common/bgheader/bgheader.go b/pkg/intel/metadata/common/bgheader/bgheader.go index 89235b3a..a070f6c5 100644 --- a/pkg/intel/metadata/common/bgheader/bgheader.go +++ b/pkg/intel/metadata/common/bgheader/bgheader.go @@ -40,18 +40,14 @@ func (bgv BootGuardVersion) String() string { func DetectBGV(r io.Reader) (BootGuardVersion, error) { var s structInfo - err := binary.Read(r, binaryOrder, s.ID[:]) + err := binary.Read(r, binaryOrder, &s) if err != nil { return 0, fmt.Errorf("unable to read field 'ID': %w", err) } - err = binary.Read(r, binaryOrder, s.Version) - if err != nil { - return 0, fmt.Errorf("unable to read field 'Version': %w", err) - } switch s.Version { case 0x10: return Version10, nil - case 0x20: + case 0x21: return Version20, nil default: return 0, fmt.Errorf("couldn't detect version") From 9c764ce563cef9de0652fb0a5f5f223c65278891 Mon Sep 17 00:00:00 2001 From: Philipp Deppenwiese Date: Thu, 12 Jan 2023 16:23:57 +0100 Subject: [PATCH 2/2] Switch to variable detection range Signed-off-by: Philipp Deppenwiese --- pkg/intel/metadata/common/bgheader/bgheader.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pkg/intel/metadata/common/bgheader/bgheader.go b/pkg/intel/metadata/common/bgheader/bgheader.go index a070f6c5..a367a8ca 100644 --- a/pkg/intel/metadata/common/bgheader/bgheader.go +++ b/pkg/intel/metadata/common/bgheader/bgheader.go @@ -44,12 +44,11 @@ func DetectBGV(r io.Reader) (BootGuardVersion, error) { if err != nil { return 0, fmt.Errorf("unable to read field 'ID': %w", err) } - switch s.Version { - case 0x10: - return Version10, nil - case 0x21: + if s.Version >= 0x20 { return Version20, nil - default: + } else if (s.Version < 0x20) && (s.Version >= 0x10) { + return Version10, nil + } else { return 0, fmt.Errorf("couldn't detect version") } }