From 0a27395aea8718387328c29379093f9aa8fd957d Mon Sep 17 00:00:00 2001 From: Saxon Date: Mon, 29 Apr 2019 13:35:58 +0930 Subject: [PATCH] protocol/rtsp: doing length check in same if but before RTSP protocol check --- protocol/rtsp/rtsp.go | 10 +++------- protocol/rtsp/rtsp_test.go | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/protocol/rtsp/rtsp.go b/protocol/rtsp/rtsp.go index 0140b569..029a57f1 100644 --- a/protocol/rtsp/rtsp.go +++ b/protocol/rtsp/rtsp.go @@ -43,7 +43,7 @@ import ( // Minimum response size to be considered valid in bytes. const minResponse = 12 -var errSmallResponse = errors.New("response too small") +var errInvalidResponse = errors.New("invalid response") // Request describes an RTSP request. type Request struct { @@ -132,12 +132,8 @@ func ReadResponse(r io.Reader) (*Response, error) { } s := scanner.Text() - if len(s) < minResponse { - return nil, errSmallResponse - } - - if s[:5] != "RTSP/" { - return nil, errors.New("invalid response") + if len(s) < minResponse || s[:5] != "RTSP/" { + return nil, errInvalidResponse } resp.Proto = "RTSP" diff --git a/protocol/rtsp/rtsp_test.go b/protocol/rtsp/rtsp_test.go index dcdf7148..f1a2257b 100644 --- a/protocol/rtsp/rtsp_test.go +++ b/protocol/rtsp/rtsp_test.go @@ -213,7 +213,7 @@ func TestMethods(t *testing.T) { for i, test := range tests { _, err = test.method(clt) - if err != nil && err != io.EOF && err != errSmallResponse { + if err != nil && err != io.EOF && err != errInvalidResponse { clientErr <- errors.New(fmt.Sprintf("error request for: %v err: %v", i, err)) } }