Skip to content

Parsing from raw functions should check that the buffer is big enough #2050

@sgmonroy

Description

@sgmonroy

As an example, MetaFromRaw should check buffer length before trying to parse anything from the buffer:

func MetaFromRaw(b []byte) (*Meta, error) {
        if len(b) < MetaLen {
                return nil, common.NewBasicError("Can't parse SCMP meta subheader, buffer is too short",
                        nil, "expected", MetaLen, "actual", len(b))
        }
        m := &Meta{}
        if err := restruct.Unpack(b, binary.BigEndian, m); err != nil {
                return nil, common.NewBasicError("Failed to unpack SCMP Metadata", err)
        }
        return m, nil
}

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions