Repository: helm/helm (go)

Issue:
`helm dependency update` SIGSEGV when dependency list item is null
<!-- If you need help or think you have found a bug, please help us with your issue by entering the following information (otherwise you can delete this text): -->

I'm learning helm and I came across this bug when doing `helm dependency update`:

`Chart.yaml`
```yaml
apiVersion: v2
name: foo-chart
version: 0.1.0
dependencies:
  - null
```

```bash
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x61adf7]

goroutine 1 [running]:
helm.sh/helm/v3/pkg/chart.(*Dependency).Validate(0x0, 0x0, 0x0)
        helm.sh/helm/v3/pkg/chart/dependency.go:56 +0x37
helm.sh/helm/v3/pkg/chart.(*Metadata).Validate(0xc0003198c0, 0x3e, 0x200)
        helm.sh/helm/v3/pkg/chart/metadata.go:129 +0x505
helm.sh/helm/v3/pkg/chart.(*Chart).Validate(...)
        helm.sh/helm/v3/pkg/chart/chart.go:125
helm.sh/helm/v3/pkg/chart/loader.LoadFiles(0xc000501880, 0x5, 0x8, 0x0, 0x0, 0xc0004aaae0)
        helm.sh/helm/v3/pkg/chart/loader/load.go:161 +0x1685
helm.sh/helm/v3/pkg/chart/loader.LoadDir(0x1f78dac, 0x1, 0x225ac48, 0xc0000d71e0, 0x0)
        helm.sh/helm/v3/pkg/chart/loader/directory.go:119 +0x2ab
helm.sh/helm/v3/pkg/downloader.(*Manager).loadChartDir(0xc000191170, 0x7ff28cf88380, 0x80, 0x88)
        helm.sh/helm/v3/pkg/downloader/manager.go:228 +0x116
helm.sh/helm/v3/pkg/downloader.(*Manager).Update(0xc000191170, 0xc000191170, 0x2)
        helm.sh/helm/v3/pkg/downloader/manager.go:154 +0x45
main.newDependencyUpdateCmd.func1(0xc000448f00, 0x2fde340, 0x0, 0x0, 0x0, 0x0)
        helm.sh/helm/v3/cmd/helm/dependency_update.go:74 +0x1da
github.com/spf13/cobra.(*Command).execute(0xc000448f00, 0x2fde340, 0x0, 0x0, 0xc000448f00, 0x2fde340)
        github.com/spf13/cobra@v1.2.1/command.go:856 +0x472
github.com/spf13/cobra.(*Command).ExecuteC(0xc00074db80, 0xc0002062e0, 0x1, 0xc00069ff60)
        github.com/spf13/cobra@v1.2.1/command.go:974 +0x375
github.com/spf13/cobra.(*Command).Execute(...)
        github.com/spf13/cobra@v1.2.1/command.go:902
main.main()
        helm.sh/helm/v3/cmd/helm/helm.go:87 +0x27b
```

The correct solution is to do:
```yaml
dependencies: null
```


Output of `helm version`:

`version.BuildInfo{Version:"v3.7.0", GitCommit:"eeac83883cb4014fe60267ec6373570374ce770b", GitTreeState:"clean", GoVersion:"go1.16.8"}`


Output of `kubectl version`:

```bash
Client Version: version.Info{Major:"1", Minor:"23", GitVersion:"v1.23.2", GitCommit:"9d142434e3af351a628bffee3939e64c681afa4d", GitTreeState:"clean", BuildDate:"2022-01-19T17:35:46Z", GoVersion:"go1.17.5", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.1", GitCommit:"5e58841cce77d4bc13713ad2b91fa0d961e69192", GitTreeState:"clean", BuildDate:"2021-05-21T23:01:33Z", GoVersion:"go1.16.4", Compiler:"gc", Platform:"linux/amd64"}
```

Pull request description:
add nil judge in  dependency and maintainer validation
Signed-off-by: wujunwei <wjw3323@live.com>

<!--  Thanks for sending a pull request!  Here are some tips for you:
1. Make sure to read the Contributing Guide before submitting your PR: https://github.com/helm/helm/blob/main/CONTRIBUTING.md
2. If this PR closes another issue, add 'closes #<issue number>' somewhere in the PR summary. GitHub will automatically close that issue when this PR gets merged. Alternatively, adding 'refs #<issue number>' will not close the issue, but help provide the reviewer more context.-->

**What this PR does / why we need it**:
fixes #11014 
**Special notes for your reviewer**:

**If applicable**:
- [ ] this PR contains documentation
- [x] this PR contains unit tests
- [x] this PR has been tested for backwards compatibility


Patch:
diff --git a/pkg/chart/dependency.go b/pkg/chart/dependency.go
index b2819f373..d9d4ee981 100644
--- a/pkg/chart/dependency.go
+++ b/pkg/chart/dependency.go
@@ -53,6 +53,9 @@ type Dependency struct {
 // the chart. This check must be done at load time before the dependency's charts are
 // loaded.
 func (d *Dependency) Validate() error {
+	if d == nil {
+		return ValidationError("dependency cannot be an empty list")
+	}
 	d.Name = sanitizeString(d.Name)
 	d.Version = sanitizeString(d.Version)
 	d.Repository = sanitizeString(d.Repository)
diff --git a/pkg/chart/metadata.go b/pkg/chart/metadata.go
index 1925e45ac..7d16ecd1b 100644
--- a/pkg/chart/metadata.go
+++ b/pkg/chart/metadata.go
@@ -34,6 +34,9 @@ type Maintainer struct {
 
 // Validate checks valid data and sanitizes string characters.
 func (m *Maintainer) Validate() error {
+	if m == nil {
+		return ValidationError("maintainer cannot be an empty list")
+	}
 	m.Name = sanitizeString(m.Name)
 	m.Email = sanitizeString(m.Email)
 	m.URL = sanitizeString(m.URL)


Test patch:
diff --git a/pkg/chart/metadata_test.go b/pkg/chart/metadata_test.go
index 9f881a4e1..98354d13f 100644
--- a/pkg/chart/metadata_test.go
+++ b/pkg/chart/metadata_test.go
@@ -72,6 +72,30 @@ func TestValidate(t *testing.T) {
 			},
 			ValidationError("dependency \"bad\" has disallowed characters in the alias"),
 		},
+		{
+			&Metadata{
+				Name:       "test",
+				APIVersion: "v2",
+				Version:    "1.0",
+				Type:       "application",
+				Dependencies: []*Dependency{
+					nil,
+				},
+			},
+			ValidationError("dependency cannot be an empty list"),
+		},
+		{
+			&Metadata{
+				Name:       "test",
+				APIVersion: "v2",
+				Version:    "1.0",
+				Type:       "application",
+				Maintainers: []*Maintainer{
+					nil,
+				},
+			},
+			ValidationError("maintainer cannot be an empty list"),
+		},
 		{
 			&Metadata{APIVersion: "v2", Name: "test", Version: "1.2.3.4"},
 			ValidationError("chart.metadata.version \"1.2.3.4\" is invalid"),