protocol/rtsp: only giving Sscanf s[5:] and then checking number of decimals read as well as error

This commit is contained in:
Saxon 2019-04-29 13:08:05 +09:30
parent 77e5d234de
commit 66bc6bbe33
1 changed files with 3 additions and 3 deletions

View File

@ -137,9 +137,9 @@ func ReadResponse(r io.Reader) (*Response, error) {
}
resp.Proto = "RTSP"
_, err = fmt.Sscanf(s[5:12], "%d.%d %d", &resp.ProtoMajor, &resp.ProtoMinor, &resp.StatusCode)
if err != nil {
return nil, err
n, err := fmt.Sscanf(s[5:], "%d.%d %d", &resp.ProtoMajor, &resp.ProtoMinor, &resp.StatusCode)
if err != nil || n != 3 {
return nil, fmt.Errorf("could not Sscanf response, error: %v", err)
}
// Read headers.