Skip to content

Commit ca4c8e3

Browse files
authored
Merge pull request #205 from mxpv/id
Add VM ID validator
2 parents 8fd1217 + 7f7605a commit ca4c8e3

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

firecracker-control/local.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"strings"
2424
"syscall"
2525

26+
"github.com/containerd/containerd/identifiers"
2627
"github.com/containerd/containerd/log"
2728
"github.com/containerd/containerd/namespaces"
2829
"github.com/containerd/containerd/plugin"
@@ -79,8 +80,7 @@ func (s *local) CreateVM(requestCtx context.Context, req *proto.CreateVMRequest)
7980
var err error
8081

8182
id := req.GetVMID()
82-
if id == "" {
83-
err = errors.New("invalid VM ID")
83+
if err := identifiers.Validate(id); err != nil {
8484
s.logger.WithError(err).Error()
8585
return nil, err
8686
}
@@ -184,6 +184,10 @@ func (s *local) CreateVM(requestCtx context.Context, req *proto.CreateVMRequest)
184184
}
185185

186186
func (s *local) shimFirecrackerClient(requestCtx context.Context, vmID string) (*fcclient.Client, error) {
187+
if err := identifiers.Validate(vmID); err != nil {
188+
return nil, errors.Wrap(err, "invalid id")
189+
}
190+
187191
socketAddr, err := fcShim.FCControlSocketAddress(requestCtx, vmID)
188192
if err != nil {
189193
err = errors.Wrap(err, "failed to get shim's fccontrol socket address")

0 commit comments

Comments
 (0)