From 77e5d234dedef770505b5df05e5c063944c44eb1 Mon Sep 17 00:00:00 2001 From: Saxon Date: Mon, 29 Apr 2019 13:03:39 +0930 Subject: [PATCH] protocol/rtsp: doing RTSP and response length check in same if --- protocol/rtsp/rtsp.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/protocol/rtsp/rtsp.go b/protocol/rtsp/rtsp.go index c12cf707..501ae5be 100644 --- a/protocol/rtsp/rtsp.go +++ b/protocol/rtsp/rtsp.go @@ -41,7 +41,7 @@ import ( ) // Minimum response size to be considered valid in bytes. -const minResponse = 2 +const minResponse = 12 var errSmallResponse = errors.New("response too small") @@ -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("not a valid RTSP response") + if s[:5] != "RTSP/" || len(s) < minResponse { + return nil, errors.New("response not valid") } resp.Proto = "RTSP"