Skip to content

Commit 58c91d6

Browse files
authored
Merge pull request #745 from kolyshkin/validate-nil
validate: fix panic
2 parents eb3432a + d58bc16 commit 58c91d6

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

validate/validate.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,21 +170,21 @@ func (v *Validator) CheckJSONSchema() (errs error) {
170170
func (v *Validator) CheckRoot() (errs error) {
171171
logrus.Debugf("check root")
172172

173-
if v.platform == "windows" && v.spec.Windows != nil {
174-
if v.spec.Windows.HyperV != nil {
173+
if v.platform == "windows" {
174+
if v.spec.Windows != nil && v.spec.Windows.HyperV != nil {
175175
if v.spec.Root != nil {
176176
errs = multierror.Append(errs,
177177
specerror.NewError(specerror.RootOnHyperVNotSet, fmt.Errorf("for Hyper-V containers, Root must not be set"), rspec.Version))
178178
}
179179
return
180180
} else if v.spec.Root == nil {
181181
errs = multierror.Append(errs,
182-
specerror.NewError(specerror.RootOnWindowsRequired, fmt.Errorf("on Windows, for Windows Server Containers, this field is REQUIRED"), rspec.Version))
182+
specerror.NewError(specerror.RootOnWindowsRequired, fmt.Errorf("on Windows, for Windows Server Containers, Root is REQUIRED"), rspec.Version))
183183
return
184184
}
185-
} else if v.platform != "windows" && v.spec.Root == nil {
185+
} else if v.spec.Root == nil {
186186
errs = multierror.Append(errs,
187-
specerror.NewError(specerror.RootOnNonWindowsRequired, fmt.Errorf("on all other platforms, this field is REQUIRED"), rspec.Version))
187+
specerror.NewError(specerror.RootOnNonWindowsRequired, fmt.Errorf("on all other platforms, Root is REQUIRED"), rspec.Version))
188188
return
189189
}
190190

validate/validate_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ func TestCheckRoot(t *testing.T) {
289289
{rspec.Spec{Windows: &rspec.Windows{HyperV: &rspec.WindowsHyperV{}}, Root: nil}, "windows", specerror.NonError},
290290
{rspec.Spec{Windows: &rspec.Windows{}, Root: &rspec.Root{Path: filepath.Join(tmpBundle, "rootfs")}}, "windows", specerror.RootPathOnWindowsGUID},
291291
{rspec.Spec{Windows: &rspec.Windows{}, Root: &rspec.Root{Path: "\\\\?\\Volume{ec84d99e-3f02-11e7-ac6c-00155d7682cf}\\"}}, "windows", specerror.NonError},
292+
{rspec.Spec{}, "windows", specerror.RootOnWindowsRequired},
292293
{rspec.Spec{Windows: &rspec.Windows{}, Root: nil}, "windows", specerror.RootOnWindowsRequired},
293294
{rspec.Spec{Root: nil}, "linux", specerror.RootOnNonWindowsRequired},
294295
{rspec.Spec{Root: &rspec.Root{Path: "maverick-rootfs"}}, "linux", specerror.RootPathOnPosixConvention},

0 commit comments

Comments
 (0)