From b85786dc56f6caa4c6ca2346f48c2a4b0d016011 Mon Sep 17 00:00:00 2001 From: Simone Gotti Date: Mon, 29 Apr 2019 10:12:03 +0200 Subject: [PATCH] datamanager: check changegroup name --- internal/datamanager/datamanager.go | 2 ++ internal/datamanager/wal.go | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/internal/datamanager/datamanager.go b/internal/datamanager/datamanager.go index ad06710..f890ef7 100644 --- a/internal/datamanager/datamanager.go +++ b/internal/datamanager/datamanager.go @@ -75,6 +75,8 @@ var ( const ( etcdChangeGroupMinRevisionRange = 1000 + + maxChangegroupNameLength = 256 ) type DataManagerConfig struct { diff --git a/internal/datamanager/wal.go b/internal/datamanager/wal.go index 5692fb2..188fd8a 100644 --- a/internal/datamanager/wal.go +++ b/internal/datamanager/wal.go @@ -19,6 +19,7 @@ import ( "container/ring" "context" "encoding/json" + "fmt" "io" "io/ioutil" "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) { + // 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 { return nil, errors.Errorf("cannot write wal: actions is empty") }