mirror of https://bitbucket.org/ausocean/av.git
protocol/rtsp: doing length check in same if but before RTSP protocol check
This commit is contained in:
parent
64f6a3d814
commit
0a27395aea
|
@ -43,7 +43,7 @@ import (
|
||||||
// Minimum response size to be considered valid in bytes.
|
// Minimum response size to be considered valid in bytes.
|
||||||
const minResponse = 12
|
const minResponse = 12
|
||||||
|
|
||||||
var errSmallResponse = errors.New("response too small")
|
var errInvalidResponse = errors.New("invalid response")
|
||||||
|
|
||||||
// Request describes an RTSP request.
|
// Request describes an RTSP request.
|
||||||
type Request struct {
|
type Request struct {
|
||||||
|
@ -132,12 +132,8 @@ func ReadResponse(r io.Reader) (*Response, error) {
|
||||||
}
|
}
|
||||||
s := scanner.Text()
|
s := scanner.Text()
|
||||||
|
|
||||||
if len(s) < minResponse {
|
if len(s) < minResponse || s[:5] != "RTSP/" {
|
||||||
return nil, errSmallResponse
|
return nil, errInvalidResponse
|
||||||
}
|
|
||||||
|
|
||||||
if s[:5] != "RTSP/" {
|
|
||||||
return nil, errors.New("invalid response")
|
|
||||||
}
|
}
|
||||||
resp.Proto = "RTSP"
|
resp.Proto = "RTSP"
|
||||||
|
|
||||||
|
|
|
@ -213,7 +213,7 @@ func TestMethods(t *testing.T) {
|
||||||
|
|
||||||
for i, test := range tests {
|
for i, test := range tests {
|
||||||
_, err = test.method(clt)
|
_, 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))
|
clientErr <- errors.New(fmt.Sprintf("error request for: %v err: %v", i, err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue