Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] vcsim: crashes when object.collect specifies invalid property path #2953

Closed
Syuparn opened this issue Sep 19, 2022 · 1 comment · Fixed by #2954
Closed

[BUG] vcsim: crashes when object.collect specifies invalid property path #2953

Syuparn opened this issue Sep 19, 2022 · 1 comment · Fixed by #2954

Comments

@Syuparn
Copy link
Contributor

Syuparn commented Sep 19, 2022

Describe the bug
vcsim crashes when govc object.collect is requested with invalid property path which is a property of an array property.

To Reproduce
Steps to reproduce the behavior:

  1. run vcsim whthout any arguments
  2. run commands below (note that config.hardware.device is an array and its properties cannot be obtained by this form)
# obtain vm's config.hardware.device, which is an array (this works as expected)
$ govc object.collect /DC0/vm/DC0_H0_VM0 config.hardware.device
config.hardware.device  []types.BaseVirtualDevice  ...

# try to obtain its property
$ govc object.collect /DC0/vm/DC0_H0_VM0 config.hardware.device.backing

Expected behavior
vcsim responds the InvalidProperty error.

$ govc object.collect /DC0/vm/DC0_H0_VM0 config.hardware.device.backing
govc: ServerFaultCode: InvalidProperty

Affected version

  • vcsim 0.29.0

Screenshots/Debug Output

vcsim crashes by panic and govc responds EOF.

$ vcsim
export GOVC_URL=https://user:pass@127.0.0.1:8989/sdk GOVC_SIM_PID=11048
2022/09/19 15:37:03 http: panic serving 127.0.0.1:54212: reflect: call of reflect.Value.FieldByName on slice Value
goroutine 81 [running]:
net/http.(*conn).serve.func1()
        /opt/hostedtoolcache/go/1.18.3/x64/src/net/http/server.go:1825 +0xbf
panic({0xd23780, 0xc00053b020})
        /opt/hostedtoolcache/go/1.18.3/x64/src/runtime/panic.go:844 +0x258
reflect.flag.mustBe(...)
        /opt/hostedtoolcache/go/1.18.3/x64/src/reflect/value.go:223
reflect.Value.FieldByName({0xc9ce20?, 0xc0001c42d8?, 0xf7b629?}, {0xc000010ae1?, 0x0?})
        /opt/hostedtoolcache/go/1.18.3/x64/src/reflect/value.go:1297 +0x1d6
github.com/vmware/govmomi/simulator.fieldValue({0xf61f80?, 0xc0001d6000?, 0xc00022ab60?}, {0xc00022ab60?, 0x38?})
        /home/runner/work/govmomi/govmomi/simulator/property_collector.go:184 +0x39c
github.com/vmware/govmomi/simulator.(*retrieveResult).collectFields(0xf61f80?, 0xc0008053b0, {0xf61f80?, 0xc0001d6000?, 0xbbc338?}, {0xc000031f90, 0x1, 0x40?}, 0xc00052d860)
        /home/runner/work/govmomi/govmomi/simulator/property_collector.go:307 +0x217
github.com/vmware/govmomi/simulator.(*retrieveResult).collect(0xc0009065a8, 0x20?, {{0xc00021ce40?, 0xc0000bfd70?}, {0xc00021ce63?, 0xc0008053b0?}})
        /home/runner/work/govmomi/govmomi/simulator/property_collector.go:358 +0x814
github.com/vmware/govmomi/simulator.(*PropertyCollector).collect.func2()
        /home/runner/work/govmomi/govmomi/simulator/property_collector.go:441 +0x34
github.com/vmware/govmomi/simulator.(*Registry).WithLock(0xee26c0?, 0x0?, {0x1121a00?, 0xc0005017a0?}, 0xc000906588)
        /home/runner/work/govmomi/govmomi/simulator/registry.go:634 +0x37
github.com/vmware/govmomi/simulator.(*Context).WithLock(...)
        /home/runner/work/govmomi/govmomi/simulator/session_manager.go:382
github.com/vmware/govmomi/simulator.(*PropertyCollector).collect(0xee4ac0?, 0xc0008053b0, 0xc0009067a0)
        /home/runner/work/govmomi/govmomi/simulator/property_collector.go:441 +0x207
github.com/vmware/govmomi/simulator.(*PropertyCollector).apply(0xc00012f020, 0xc0008053b0, 0xc00044eff0)
        /home/runner/work/govmomi/govmomi/simulator/property_collector.go:597 +0x218
github.com/vmware/govmomi/simulator.(*PropertyCollector).WaitForUpdatesEx.func1()
        /home/runner/work/govmomi/govmomi/simulator/property_collector.go:661 +0x32
github.com/vmware/govmomi/simulator.(*PropertyCollector).WaitForUpdatesEx(0xc00012f020, 0xc0008053b0, 0xc0001dd800)
        /home/runner/work/govmomi/govmomi/simulator/property_collector.go:671 +0x33a
reflect.Value.call({0xf4aa00?, 0xc00012f020?, 0x18?}, {0xf7bdc7, 0x4}, {0xc00044ef60, 0x2, 0xc000907320?})
        /opt/hostedtoolcache/go/1.18.3/x64/src/reflect/value.go:556 +0x845
reflect.Value.Call({0xf4aa00?, 0xc00012f020?, 0x44b7b4?}, {0xc00044ef60, 0x2, 0x2})
        /opt/hostedtoolcache/go/1.18.3/x64/src/reflect/value.go:339 +0xbf
github.com/vmware/govmomi/simulator.(*Service).call.func1()
        /home/runner/work/govmomi/govmomi/simulator/simulator.go:218 +0x3a
github.com/vmware/govmomi/simulator.(*Registry).WithLock(0xf78600?, 0xc00053afa8?, {0x111c520?, 0xc00012f020?}, 0xc0009075b8)
        /home/runner/work/govmomi/govmomi/simulator/registry.go:634 +0x37
github.com/vmware/govmomi/simulator.(*Service).call(0xc00007e540, 0xc0008053b0, 0xc00054d480)
        /home/runner/work/govmomi/govmomi/simulator/simulator.go:217 +0xf10
github.com/vmware/govmomi/simulator.(*Service).ServeSDK(0xc00007e540, {0x1123c70, 0xc000255ea0}, 0xc0005c3600)
        /home/runner/work/govmomi/govmomi/simulator/simulator.go:492 +0x549
net/http.HandlerFunc.ServeHTTP(0xbc71482f627baab2?, {0x1123c70?, 0xc000255ea0?}, 0x0?)
        /opt/hostedtoolcache/go/1.18.3/x64/src/net/http/server.go:2084 +0x2f
net/http.(*ServeMux).ServeHTTP(0x0?, {0x1123c70, 0xc000255ea0}, 0xc0005c3600)
        /opt/hostedtoolcache/go/1.18.3/x64/src/net/http/server.go:2462 +0x149
net/http.serverHandler.ServeHTTP({0x1122d88?}, {0x1123c70, 0xc000255ea0}, 0xc0005c3600)
        /opt/hostedtoolcache/go/1.18.3/x64/src/net/http/server.go:2916 +0x43b
net/http.(*conn).serve(0xc0001da280, {0x1124060, 0xc0002080c0})
        /opt/hostedtoolcache/go/1.18.3/x64/src/net/http/server.go:1966 +0x5d7
created by net/http.(*Server).Serve
        /opt/hostedtoolcache/go/1.18.3/x64/src/net/http/server.go:3071 +0x4db
$ govc object.collect /DC0/vm/DC0_H0_VM0 config.hardware.device.backing
govc: Post "https://127.0.0.1:8989/sdk": EOF

Additional context

@Syuparn
Copy link
Contributor Author

Syuparn commented Sep 19, 2022

By the way, is there any way to obtain specific properties of an array property? If it exists, vcsim should also handle this.

Syuparn added a commit to Syuparn/govmomi that referenced this issue Sep 19, 2022
Closes: vmware#2953
Signed-off-by: syuparn <s.hello.spagetti@gmail.com>
priyanka19-98 pushed a commit to priyanka19-98/govmomi that referenced this issue Jan 17, 2024
Closes: vmware#2953
Signed-off-by: syuparn <s.hello.spagetti@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant