Browse Source

check path name in configuration

pull/80/head
aler9 5 years ago
parent
commit
edb2c1f5cd
  1. 7
      client.go
  2. 5
      conf.go
  3. 11
      utils.go

7
client.go

@ -355,8 +355,9 @@ func (c *client) handleRequest(req *gortsplib.Request) bool { @@ -355,8 +355,9 @@ func (c *client) handleRequest(req *gortsplib.Request) bool {
return false
}
if strings.Index(path, "/") >= 0 {
c.writeResError(req, gortsplib.StatusBadRequest, fmt.Errorf("slashes in the path are not supported (%s)", path))
err := checkPathName(path)
if err != nil {
c.writeResError(req, gortsplib.StatusBadRequest, fmt.Errorf("invalid path name: %s (%s)", err, path))
return false
}
@ -367,7 +368,7 @@ func (c *client) handleRequest(req *gortsplib.Request) bool { @@ -367,7 +368,7 @@ func (c *client) handleRequest(req *gortsplib.Request) bool {
return false
}
err := c.authenticate(confp.publishIpsParsed, confp.PublishUser, confp.PublishPass, req)
err = c.authenticate(confp.publishIpsParsed, confp.PublishUser, confp.PublishPass, req)
if err != nil {
if err == errAuthCritical {
return false

5
conf.go

@ -180,6 +180,11 @@ func loadConf(fpath string, stdin io.Reader) (*conf, error) { @@ -180,6 +180,11 @@ func loadConf(fpath string, stdin io.Reader) (*conf, error) {
confp = conf.Paths[name]
}
err := checkPathName(name)
if err != nil {
return nil, fmt.Errorf("invalid path name: %s (%s)", err, name)
}
if confp.Source == "" {
confp.Source = "record"
}

11
utils.go

@ -3,6 +3,7 @@ package main @@ -3,6 +3,7 @@ package main
import (
"fmt"
"net"
"regexp"
"strconv"
"strings"
@ -161,3 +162,13 @@ func makeIpKey(ip net.IP) ipKey { @@ -161,3 +162,13 @@ func makeIpKey(ip net.IP) ipKey {
}
return ret
}
var rePathName = regexp.MustCompile("^[0-9a-zA-Z_-]+$")
func checkPathName(name string) error {
if !rePathName.MatchString(name) {
return fmt.Errorf("can contain only alfanumeric characters, underscore or minus")
}
return nil
}

Loading…
Cancel
Save