From b779f7e9dce68c761382b461a121bec24fbb87a7 Mon Sep 17 00:00:00 2001 From: Siarhiej Siemianczuk Date: Tue, 17 Sep 2024 18:48:50 +0300 Subject: [PATCH 1/4] pkg/cbfs: fix error string (errors should not be capitalized) Signed-off-by: Siarhiej Siemianczuk --- pkg/cbfs/file.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cbfs/file.go b/pkg/cbfs/file.go index a9e3f984..25671688 100644 --- a/pkg/cbfs/file.go +++ b/pkg/cbfs/file.go @@ -193,5 +193,5 @@ func (f *File) Decompress() ([]byte, error) { compressor := compression.LZ4{} return compressor.Decode(f.FData) } - return nil, fmt.Errorf("Unknown compression") + return nil, fmt.Errorf("unknown compression") } From bf5f8e52621579bf0df1152ec7b6e4dbda80d48d Mon Sep 17 00:00:00 2001 From: Siarhiej Siemianczuk Date: Tue, 17 Sep 2024 18:54:34 +0300 Subject: [PATCH 2/4] pkg/cbfs: wrap errors and fix capitalization Signed-off-by: Siarhiej Siemianczuk --- pkg/cbfs/image.go | 10 +++++----- pkg/cbfs/payload.go | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/cbfs/image.go b/pkg/cbfs/image.go index 5fe80f01..b407e4b7 100644 --- a/pkg/cbfs/image.go +++ b/pkg/cbfs/image.go @@ -36,7 +36,7 @@ func NewImage(rs io.ReadSeeker) (*Image, error) { // ReadSeeker on a []byte. b, err := io.ReadAll(rs) if err != nil { - return nil, fmt.Errorf("ReadAll: %v", err) + return nil, fmt.Errorf("failed to read: %w", err) } in := bytes.NewReader(b) f, m, err := fmap.Read(in) @@ -53,7 +53,7 @@ func NewImage(rs io.ReadSeeker) (*Image, error) { } } if i.Area == nil { - return nil, fmt.Errorf("No CBFS in fmap") + return nil, fmt.Errorf("no CBFS in fmap") } r := io.NewSectionReader(in, int64(i.Area.Offset), int64(i.Area.Size)) @@ -89,7 +89,7 @@ func NewImage(rs io.ReadSeeker) (*Image, error) { } Debug("Segment: %v", s) if err := s.Read(bytes.NewReader(f.FData)); err != nil { - return nil, fmt.Errorf("Reading %#x byte subheader, type %v: %v", len(f.FData), f.Type, err) + return nil, fmt.Errorf("reading %#x byte subheader, type %v: %w", len(f.FData), f.Type, err) } Debug("Segment was readable") i.Segs = append(i.Segs, s) @@ -120,7 +120,7 @@ func (i *Image) Update() error { return err } if _, err := b.Write(s.GetFile().Attr); err != nil { - return fmt.Errorf("Writing attr to cbfs record for %v: %v", s, err) + return fmt.Errorf("writing attr to cbfs record for %v: %w", s, err) } if err := s.Write(&b); err != nil { return err @@ -128,7 +128,7 @@ func (i *Image) Update() error { // This error should not happen but we need to check just in case. end := uint32(len(b.Bytes())) + s.GetFile().RecordStart if end > i.Area.Size { - return fmt.Errorf("Region [%#x, %#x] outside of CBFS [%#x, %#x]", s.GetFile().RecordStart, end, s.GetFile().RecordStart, i.Area.Size) + return fmt.Errorf("region [%#x, %#x] outside of CBFS [%#x, %#x]", s.GetFile().RecordStart, end, s.GetFile().RecordStart, i.Area.Size) } Debug("Copy %s %d bytes to i.Data[%d]", s.GetFile().Type.String(), len(b.Bytes()), i.Area.Offset+s.GetFile().RecordStart) diff --git a/pkg/cbfs/payload.go b/pkg/cbfs/payload.go index c1eae89a..50362150 100644 --- a/pkg/cbfs/payload.go +++ b/pkg/cbfs/payload.go @@ -38,7 +38,7 @@ func (p *PayloadRecord) Read(in io.ReadSeeker) error { // Seek to offset (after the header); the remainder is the actual payload. offset, err := in.Seek(0, io.SeekCurrent) if err != nil { - return fmt.Errorf("Finding location in stream: %v", err) + return fmt.Errorf("finding location in stream: %w", err) } bodySize := int64(p.Size) - offset Debug("Payload size: %v, body size: %v, offset: %v", p.Size, bodySize, offset) From 5a2b2fcb840e96e6fea700fb60e3bf91bfadc7c6 Mon Sep 17 00:00:00 2001 From: Siarhiej Siemianczuk Date: Tue, 17 Sep 2024 18:59:41 +0300 Subject: [PATCH 3/4] pkg/intel/microcode: wrap errors and fix capitalization Signed-off-by: Siarhiej Siemianczuk --- pkg/intel/microcode/microcode.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pkg/intel/microcode/microcode.go b/pkg/intel/microcode/microcode.go index 093d8613..242a8c71 100644 --- a/pkg/intel/microcode/microcode.go +++ b/pkg/intel/microcode/microcode.go @@ -86,26 +86,26 @@ func ParseIntelMicrocode(r io.Reader) (*Microcode, error) { var m Microcode if err := binary.Read(r, binary.LittleEndian, &m.Header); err != nil { - return nil, fmt.Errorf("Failed to read header: %v", err) + return nil, fmt.Errorf("failed to read header: %w", err) } // Sanitychecks if getTotalSize(m.Header) < getDataSize(m.Header)+uint32(binary.Size(Header{})) { - return nil, fmt.Errorf("Bad data file size") + return nil, fmt.Errorf("bad data file size") } if m.HeaderLoaderRevision != 1 || m.HeaderVersion != 1 { - return nil, fmt.Errorf("Invalid version or revision") + return nil, fmt.Errorf("invalid version or revision") } if getDataSize(m.Header)%4 > 0 { - return nil, fmt.Errorf("Data size not 32bit aligned") + return nil, fmt.Errorf("data size not 32bit aligned") } if getTotalSize(m.Header)%4 > 0 { - return nil, fmt.Errorf("Total size not 32bit aligned") + return nil, fmt.Errorf("total size not 32bit aligned") } // Read data m.Data = make([]byte, getDataSize(m.Header)) if err := binary.Read(r, binary.LittleEndian, &m.Data); err != nil { - return nil, fmt.Errorf("Failed to read data: %v", err) + return nil, fmt.Errorf("failed to read data: %w", err) } // Calculcate checksum @@ -123,7 +123,7 @@ func ParseIntelMicrocode(r io.Reader) (*Microcode, error) { checksum += data } if checksum != 0 { - return nil, fmt.Errorf("Checksum is not null: %#x", checksum) + return nil, fmt.Errorf("checksum is not null: %#x", checksum) } if getTotalSize(m.Header) <= getDataSize(m.Header)+uint32(binary.Size(Header{})) { @@ -132,12 +132,12 @@ func ParseIntelMicrocode(r io.Reader) (*Microcode, error) { // Read extended header if err := binary.Read(r, binary.LittleEndian, &m.ExtSigTable); err != nil { - return nil, fmt.Errorf("Failed to read extended sig table: %v", err) + return nil, fmt.Errorf("failed to read extended sig table: %w", err) } for i := uint32(0); i < m.ExtSigTable.Count; i++ { var signature ExtendedSignature if err := binary.Read(r, binary.LittleEndian, &signature); err != nil { - return nil, fmt.Errorf("Failed to read extended signature: %v", err) + return nil, fmt.Errorf("failed to read extended signature: %w", err) } m.ExtendedSignatures = append(m.ExtendedSignatures, signature) } @@ -160,7 +160,7 @@ func ParseIntelMicrocode(r io.Reader) (*Microcode, error) { checksum += data } if checksum != 0 { - return nil, fmt.Errorf("Extended header checksum is not null: %#x", checksum) + return nil, fmt.Errorf("extended header checksum is not null: %#x", checksum) } return &m, nil From eb0f25daf414c4c30d25e88fc344c198b4025671 Mon Sep 17 00:00:00 2001 From: Siarhiej Siemianczuk Date: Tue, 17 Sep 2024 19:01:20 +0300 Subject: [PATCH 4/4] pkg/uefi: fix error capitalization Signed-off-by: Siarhiej Siemianczuk --- pkg/uefi/file.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/uefi/file.go b/pkg/uefi/file.go index 4820716a..78a044a6 100644 --- a/pkg/uefi/file.go +++ b/pkg/uefi/file.go @@ -179,7 +179,7 @@ type ThreeUint8 [3]uint8 func (t *ThreeUint8) UnmarshalJSON(b []byte) error { if copy(t[:], b) == 0 { - return fmt.Errorf("Cannot unmarshal 3 uint8 from %v\n", b) + return fmt.Errorf("cannot unmarshal 3 uint8 from %v", b) } return nil }