protocol/rtsp: doing RTSP and response length check in same if

This commit is contained in:
Saxon 2019-04-29 13:03:39 +09:30
parent ba5a0d898c
commit 77e5d234de
1 changed files with 3 additions and 7 deletions

View File

@ -41,7 +41,7 @@ import (
) )
// Minimum response size to be considered valid in bytes. // Minimum response size to be considered valid in bytes.
const minResponse = 2 const minResponse = 12
var errSmallResponse = errors.New("response too small") var errSmallResponse = errors.New("response too small")
@ -132,12 +132,8 @@ func ReadResponse(r io.Reader) (*Response, error) {
} }
s := scanner.Text() s := scanner.Text()
if len(s) < minResponse { if s[:5] != "RTSP/" || len(s) < minResponse {
return nil, errSmallResponse return nil, errors.New("response not valid")
}
if s[:5] != "RTSP/" {
return nil, errors.New("not a valid RTSP response")
} }
resp.Proto = "RTSP" resp.Proto = "RTSP"