Browse Source

check path name in configuration

pull/80/head
aler9 6 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 {
return false return false
} }
if strings.Index(path, "/") >= 0 { err := checkPathName(path)
c.writeResError(req, gortsplib.StatusBadRequest, fmt.Errorf("slashes in the path are not supported (%s)", path)) if err != nil {
c.writeResError(req, gortsplib.StatusBadRequest, fmt.Errorf("invalid path name: %s (%s)", err, path))
return false return false
} }
@ -367,7 +368,7 @@ func (c *client) handleRequest(req *gortsplib.Request) bool {
return false 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 != nil {
if err == errAuthCritical { if err == errAuthCritical {
return false return false

5
conf.go

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

11
utils.go

@ -3,6 +3,7 @@ package main
import ( import (
"fmt" "fmt"
"net" "net"
"regexp"
"strconv" "strconv"
"strings" "strings"
@ -161,3 +162,13 @@ func makeIpKey(ip net.IP) ipKey {
} }
return ret 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