From 26bcb7255cf245638a9162ab66c46b64387ef49d Mon Sep 17 00:00:00 2001 From: Kathryn Baldauf Date: Wed, 9 Dec 2020 18:09:20 -0800 Subject: [PATCH] Fix potential panic in createLCOWSpec when no network ns is set Signed-off-by: Kathryn Baldauf --- internal/hcsoci/hcsdoc_lcow.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/internal/hcsoci/hcsdoc_lcow.go b/internal/hcsoci/hcsdoc_lcow.go index 82e50307ad..7352557c1d 100644 --- a/internal/hcsoci/hcsdoc_lcow.go +++ b/internal/hcsoci/hcsdoc_lcow.go @@ -29,7 +29,7 @@ func createLCOWSpec(coi *createOptionsInternal) (*specs.Spec, error) { spec.Windows = nil if coi.Spec.Windows != nil { setWindowsNetworkNamespace(coi, spec) - spec.Windows.Devices = coi.Spec.Windows.Devices + setWindowsDevices(coi, spec) } // Hooks are not supported (they should be run in the host) @@ -52,14 +52,24 @@ func createLCOWSpec(coi *createOptionsInternal) (*specs.Spec, error) { func setWindowsNetworkNamespace(coi *createOptionsInternal, spec *specs.Spec) { if coi.Spec.Windows.Network != nil && coi.Spec.Windows.Network.NetworkNamespace != "" { - spec.Windows = &specs.Windows{ - Network: &specs.WindowsNetwork{ - NetworkNamespace: coi.Spec.Windows.Network.NetworkNamespace, - }, + if spec.Windows == nil { + spec.Windows = &specs.Windows{} + } + spec.Windows.Network = &specs.WindowsNetwork{ + NetworkNamespace: coi.Spec.Windows.Network.NetworkNamespace, } } } +func setWindowsDevices(coi *createOptionsInternal, spec *specs.Spec) { + if coi.Spec.Windows.Devices != nil { + if spec.Windows == nil { + spec.Windows = &specs.Windows{} + } + spec.Windows.Devices = coi.Spec.Windows.Devices + } +} + type linuxHostedSystem struct { SchemaVersion *hcsschema.Version OciBundlePath string