server: fix crash with invalid SETUP request (bluenviron/mediamtx#4025) (#652)

This commit is contained in:
Alessandro Ros
2024-12-08 18:58:13 +01:00
committed by GitHub
parent fb61e9a922
commit db334b3a8d
3 changed files with 92 additions and 39 deletions

View File

@@ -76,11 +76,17 @@ func getPathAndQueryAndTrackID(u *base.URL) (string, string, string, error) {
if strings.HasSuffix(u.RawQuery, "/") {
return u.Path, u.RawQuery[:len(u.RawQuery)-1], "0", nil
}
if strings.HasSuffix(u.Path[1:], "/") {
if len(u.Path) >= 1 && strings.HasSuffix(u.Path[1:], "/") {
return u.Path[:len(u.Path)-1], u.RawQuery, "0", nil
}
return "", "", "", liberrors.ErrServerPathNoSlash{}
// special case for empty path
if u.Path == "" || u.Path == "/" {
return u.Path, u.RawQuery, "0", nil
}
// no slash at the end of the path.
return "", "", "", liberrors.ErrServerInvalidSetupPath{}
}
// used for SETUP when recording