cmd/govulncheck: fix bug in platforms row when printing results

When there are specific OSs for a vuln but no architecure, and vice
versa, we would not printing anything in the platforms row. This CL
fixes that issue.

In such cases, we just list the OSs, or archs in vice versa case. An
alternative was to print something like "windows/*", but that seemed
confusing. Having a row like "Platforms: windows" seams clear to the
user.

Change-Id: I41b9865353571b8d225d198ba172a566fa992852
Reviewed-on: https://go-review.googlesource.com/c/vuln/+/460423
Reviewed-by: Julie Qiu <julieqiu@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Zvonimir Pavlinovic <zpavlinovic@google.com>
diff --git a/cmd/govulncheck/print.go b/cmd/govulncheck/print.go
index 9d74b95..e089846 100644
--- a/cmd/govulncheck/print.go
+++ b/cmd/govulncheck/print.go
@@ -162,10 +162,25 @@
 	for _, a := range e.Affected {
 		for _, p := range a.EcosystemSpecific.Imports {
 			for _, os := range p.GOOS {
+				// In case there are no specific architectures,
+				// just list the os entries.
+				if len(p.GOARCH) == 0 {
+					platforms[os] = true
+					continue
+				}
+				// Otherwise, list all the os+arch combinations.
 				for _, arch := range p.GOARCH {
 					platforms[os+"/"+arch] = true
 				}
 			}
+
+			// Cover the case where there are no specific
+			// operating systems listed.
+			if len(p.GOOS) == 0 {
+				for _, arch := range p.GOARCH {
+					platforms[arch] = true
+				}
+			}
 		}
 	}
 	keys := maps.Keys(platforms)
diff --git a/cmd/govulncheck/print_test.go b/cmd/govulncheck/print_test.go
index 2f8b089..cc04d14 100644
--- a/cmd/govulncheck/print_test.go
+++ b/cmd/govulncheck/print_test.go
@@ -58,6 +58,40 @@
 			},
 			want: "linux/amd64, windows/amd64",
 		},
+		{
+			entry: &osv.Entry{
+				ID: "two-os-only",
+				Affected: []osv.Affected{{
+					Package: osv.Package{Name: "golang.org/vmod"},
+					Ranges:  osv.Affects{{Type: osv.TypeSemver, Events: []osv.RangeEvent{{Introduced: "1.2.0"}}}},
+					EcosystemSpecific: osv.EcosystemSpecific{
+						Imports: []osv.EcosystemSpecificImport{
+							{
+								GOOS: []string{"windows, linux"},
+							},
+						},
+					},
+				}},
+			},
+			want: "windows, linux",
+		},
+		{
+			entry: &osv.Entry{
+				ID: "one-arch-only",
+				Affected: []osv.Affected{{
+					Package: osv.Package{Name: "golang.org/vmod"},
+					Ranges:  osv.Affects{{Type: osv.TypeSemver, Events: []osv.RangeEvent{{Introduced: "1.2.0"}}}},
+					EcosystemSpecific: osv.EcosystemSpecific{
+						Imports: []osv.EcosystemSpecificImport{
+							{
+								GOOS: []string{"amd64"},
+							},
+						},
+					},
+				}},
+			},
+			want: "amd64",
+		},
 	} {
 		t.Run(test.entry.ID, func(t *testing.T) {
 			got := platforms(test.entry)