protocol/rtsp: doing length check in same if but before RTSP protocol check

This commit is contained in:
Saxon 2019-04-29 13:35:58 +09:30
parent 64f6a3d814
commit 0a27395aea
2 changed files with 4 additions and 8 deletions

View File

@ -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"

View File

@ -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))
}
}