Skip to content

Commit 8a127a6

Browse files
authored
pkg/intel/metadara: fix bgheader parser, add multiversion detection (#397)
* parse entire struct * Switch to variable detection range Signed-off-by: Philipp Deppenwiese <zaolin.daisuki@gmail.com>
1 parent 8e9c749 commit 8a127a6

1 file changed

Lines changed: 5 additions & 10 deletions

File tree

pkg/intel/metadata/common/bgheader/bgheader.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,15 @@ func (bgv BootGuardVersion) String() string {
4040

4141
func DetectBGV(r io.Reader) (BootGuardVersion, error) {
4242
var s structInfo
43-
err := binary.Read(r, binaryOrder, s.ID[:])
43+
err := binary.Read(r, binaryOrder, &s)
4444
if err != nil {
4545
return 0, fmt.Errorf("unable to read field 'ID': %w", err)
4646
}
47-
err = binary.Read(r, binaryOrder, s.Version)
48-
if err != nil {
49-
return 0, fmt.Errorf("unable to read field 'Version': %w", err)
50-
}
51-
switch s.Version {
52-
case 0x10:
53-
return Version10, nil
54-
case 0x20:
47+
if s.Version >= 0x20 {
5548
return Version20, nil
56-
default:
49+
} else if (s.Version < 0x20) && (s.Version >= 0x10) {
50+
return Version10, nil
51+
} else {
5752
return 0, fmt.Errorf("couldn't detect version")
5853
}
5954
}

0 commit comments

Comments
 (0)