Merged in better-rtmp-url-checking (pull request #172)

Made parseURL() more robust.

Approved-by: Saxon Milton <saxon.milton@gmail.com>
Approved-by: kortschak <dan@kortschak.io>
This commit is contained in:
Alan Noble 2019-03-15 07:15:18 +00:00 committed by Saxon Milton
commit c102fa06a1
2 changed files with 8 additions and 12 deletions

View File

@ -75,20 +75,16 @@ func parseURL(addr string) (protocol int32, host string, port uint16, app, playp
port = uint16(pi) port = uint16(pi)
} }
if !path.IsAbs(u.Path) { if len(u.Path) < 1 || !path.IsAbs(u.Path) {
return protocol, host, port, app, playpath, nil
}
elems := strings.SplitN(u.Path[1:], "/", 3)
app = elems[0]
if len(elems[len(elems)-1]) == 0 {
elems = elems[:len(elems)-1]
}
if app == "" || len(elems) < 2 {
return protocol, host, port, app, playpath, errInvalidURL return protocol, host, port, app, playpath, errInvalidURL
} }
elems := strings.SplitN(u.Path[1:], "/", 3)
if len(elems) < 2 || elems[0] == "" || elems[1] == "" {
return protocol, host, port, app, playpath, errInvalidURL
}
app = elems[0]
playpath = path.Join(elems[1:]...) playpath = path.Join(elems[1:]...)
switch ext := path.Ext(playpath); ext { switch ext := path.Ext(playpath); ext {
case ".f4v", ".mp4": case ".f4v", ".mp4":
playpath = playpath[:len(playpath)-len(ext)] playpath = playpath[:len(playpath)-len(ext)]

View File

@ -41,7 +41,7 @@ var parseURLTests = []struct {
}{ }{
{ {
url: "rtmp://addr", url: "rtmp://addr",
wantHost: "addr", wantErr: errInvalidURL,
}, },
{ {
url: "rtmp://addr/", url: "rtmp://addr/",