RTCP: test for unmarshaling nil packet

This commit is contained in:
Max Hawkins
2018-09-10 22:05:38 -07:00
committed by Michiel De Backker
parent 74e2d1e3de
commit 894296d9ab
2 changed files with 10 additions and 1 deletions

View File

@@ -46,6 +46,7 @@ const (
var ( var (
errInvalidVersion = errors.New("invalid version") errInvalidVersion = errors.New("invalid version")
errInvalidReportCount = errors.New("invalid report count") errInvalidReportCount = errors.New("invalid report count")
errHeaderTooShort = errors.New("rtcp header too short")
) )
// Marshal encodes the Header in binary // Marshal encodes the Header in binary
@@ -83,7 +84,7 @@ func (h Header) Marshal() ([]byte, error) {
// Unmarshal decodes the Header from binary // Unmarshal decodes the Header from binary
func (h *Header) Unmarshal(rawPacket []byte) error { func (h *Header) Unmarshal(rawPacket []byte) error {
if len(rawPacket) < headerLength { if len(rawPacket) < headerLength {
return errors.Errorf("RTCP header size insufficient; %d < %d", len(rawPacket), headerLength) return errHeaderTooShort
} }
/* /*

View File

@@ -29,6 +29,14 @@ func TestHeaderUnmarshal(t *testing.T) {
t.Fatalf("Unmarshal: got %#v, want %#v", got, want) t.Fatalf("Unmarshal: got %#v, want %#v", got, want)
} }
} }
func TestHeaderUnmarshalNil(t *testing.T) {
var header Header
err := header.Unmarshal(nil)
if got, want := err, errHeaderTooShort; got != want {
t.Fatalf("unmarshal nil header: err = %v, want %v", got, want)
}
}
func TestHeaderRoundTrip(t *testing.T) { func TestHeaderRoundTrip(t *testing.T) {
for _, test := range []struct { for _, test := range []struct {
Name string Name string