datamanager: check changegroup name

This commit is contained in:
Simone Gotti 2019-04-29 10:12:03 +02:00
parent 340cc15268
commit b85786dc56
2 changed files with 15 additions and 0 deletions

View File

@ -75,6 +75,8 @@ var (
const ( const (
etcdChangeGroupMinRevisionRange = 1000 etcdChangeGroupMinRevisionRange = 1000
maxChangegroupNameLength = 256
) )
type DataManagerConfig struct { type DataManagerConfig struct {

View File

@ -19,6 +19,7 @@ import (
"container/ring" "container/ring"
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"path" "path"
@ -424,6 +425,18 @@ func (d *DataManager) WriteWal(ctx context.Context, actions []*Action, cgt *Chan
} }
func (d *DataManager) WriteWalAdditionalOps(ctx context.Context, actions []*Action, cgt *ChangeGroupsUpdateToken, cmp []etcdclientv3.Cmp, then []etcdclientv3.Op) (*ChangeGroupsUpdateToken, error) { func (d *DataManager) WriteWalAdditionalOps(ctx context.Context, actions []*Action, cgt *ChangeGroupsUpdateToken, cmp []etcdclientv3.Cmp, then []etcdclientv3.Op) (*ChangeGroupsUpdateToken, error) {
// check changegroups name
if cgt != nil {
for cgName := range cgt.ChangeGroupsRevisions {
if strings.Contains(cgName, "/") {
return nil, fmt.Errorf(`changegroup name %q must not contain "/"`, cgName)
}
if len(cgName) > maxChangegroupNameLength {
return nil, fmt.Errorf("changegroup name %q too long", cgName)
}
}
}
if len(actions) == 0 { if len(actions) == 0 {
return nil, errors.Errorf("cannot write wal: actions is empty") return nil, errors.Errorf("cannot write wal: actions is empty")
} }