Vehicles: validate config name (#11210)

This commit is contained in:
andig 2023-12-23 15:02:52 +01:00 • committed by GitHub
parent 96ef894ccc
commit 26ed34081d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -7,6 +7,7 @@ import (
"fmt"
"net"
"net/http"
"regexp"
"slices"
"strconv"
"strings"
@ -68,6 +69,8 @@ var conf = globalConfig{
},
}
var nameRE = regexp.MustCompile(`^[a-zA-Z0-9_.:-]+$`)
type globalConfig struct {
Network networkConfig
Log string
@ -271,6 +274,10 @@ func configureChargers(static []config.Named, names ...string) error {
}
func vehicleInstance(cc config.Named) (api.Vehicle, error) {
if !nameRE.MatchString(cc.Name) {
return nil, fmt.Errorf("vehicle name must not contain special characters or spaces: %s", cc.Name)
}
instance, err := vehicle.NewFromConfig(cc.Type, cc.Other)
if err != nil {
var ce *util.ConfigError