Skip to content

[BUG] vcsim: createVM crashes when VM name contains /Β #2873

@Syuparn

Description

@Syuparn

Describe the bug

CreateVM request crashes vcsim when the vm name contains /.

To Reproduce

  1. start vcsim without options
  2. execute govc command below
$ govc vm.create -cluster DC0_C0 -net DC0_DVPG0 "foo/bar"

Expected behavior

A new vm named foo%2fbar is created. Special character / is escaped automatically.

$ govc vm.create -cluster DC0_C0 -net DC0_DVPG0 "foo/bar"
$ govc vm.info "foo%2fbar"
Name:           foo%2fbar
  Path:         /DC0/vm/foo%2fbar
  UUID:         4221b558-d433-d07d-af97-b56a71f990c1
  Guest name:   Other (32-bit)
  Memory:       1024MB
  CPU:          1 vCPU(s)
  Power state:  poweredOn
  Boot time:    2022-06-10 12:57:15 +0000 UTC
  IP address:
  Host:         192.168.1.200

Affected version

  • vcsim v0.28.0

Screenshots/Debug Output
If applicable, add screenshots or debug output to help explain your problem.

vcsim raises panic due to nil pointer dereference while creating the VM.

$ govc vm.create -cluster DC0_C0 -net DC0_DVPG0 "foo/bar"
govc: Post "https://127.0.0.1:8989/sdk": read tcp 127.0.0.1:40060->127.0.0.1:8989: read: connection reset by peer
$ vcsim
export GOVC_URL=https://user:[email protected]:8989/sdk GOVC_SIM_PID=228005
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xac4977]

goroutine 103 [running]:
github.com/vmware/govmomi/simulator.(*VirtualMachine).Reference(0x0?)
        <autogenerated>:1 +0x17
github.com/vmware/govmomi/simulator.folderRemoveChild(0xc0008c01b0, 0xc000364b60, {0x110c420, 0x0})
        /home/runner/work/govmomi/govmomi/simulator/folder.go:112 +0x38
github.com/vmware/govmomi/simulator.(*createVM).Run(0xc0002c96a0, 0x0?)
        /home/runner/work/govmomi/govmomi/simulator/folder.go:372 +0x555
github.com/vmware/govmomi/simulator.(*Task).Run.func1()
        /home/runner/work/govmomi/govmomi/simulator/task.go:117 +0x6c
created by github.com/vmware/govmomi/simulator.(*Task).Run
        /home/runner/work/govmomi/govmomi/simulator/task.go:115 +0x238

Additional context

This seems due to unescaped special characters (like #2717). %, /, and \ in VM names should be escaped like folder names.

# In vCenter
$ govc vm.create -net DC0_DVPG0 "/\%"
$ govc vm.info "%2f%5c%25"
Name:           %2f%5c%25
  Path:         /DC0/vm/%2f%5c%25
  UUID:         4221d450-2e38-eadf-dd45-29b6a13a9b49
  Guest name:   Other (32-bit)
  Memory:       1024MB
  CPU:          1 vCPU(s)
  Power state:  poweredOn
  Boot time:    2022-06-10 13:13:34 +0000 UTC
  IP address:
  Host:         192.168.1.200

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions