Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@willmurphyscode
Copy link
Contributor

@willmurphyscode willmurphyscode commented Jul 17, 2023

Previously, the wrong path would get passed, and the template file would get truncated.

Fixes #1388

Manual testing done:

❯ go run cmd/grype/main.go -o template=foo.csv -o json -t templates/csv.tmpl alpine:latest
 ✔ Vulnerability DB                [no update available]  
 ✔ Loaded image                                                                                                                                                                                               alpine:latest
 ✔ Parsed image                                                                                                                                     sha256:5053b247d78b5e43b5543fec77c856ce70b8dc705d9f38336fa77736f25ff47c
 ✔ Cataloged packages              [16 packages]  
 ✔ Scanned for vulnerabilities     [2 vulnerabilities]  
   ├── 0 critical, 0 high, 0 medium, 0 low, 0 negligible (2 unknown)
   └── 2 fixed
# json got written to stdout:
{
 "matches": [
  {
   "vulnerability": {
    "id": "CVE-2023-2975",
    "dataSource": "http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2023-2975",
    "namespace": "alpine:distro:alpine:3.18",
    "severity": "Unknown",
    "urls": [
... snip
# csv got written
❯ cat foo.csv 
"Package","Version Installed","Vulnerability ID","Severity"
"libcrypto3","3.1.1-r1","CVE-2023-2975","Unknown"
"libssl3","3.1.1-r1","CVE-2023-2975","Unknown"
# template file used did not get truncated
❯ cat templates/csv.tmpl 
"Package","Version Installed","Vulnerability ID","Severity"
{{- range .Matches}}
"{{.Artifact.Name}}","{{.Artifact.Version}}","{{.Vulnerability.ID}}","{{.Vulnerability.Severity}}"
{{- end}}

Testing that --file still works

 go run cmd/grype/main.go -o template=foo.csv -o json --file test.json -t templates/csv.tmpl alpine:latest
 ✔ Vulnerability DB                [no update available]  
 ✔ Loaded image                                                                                                                                                                                               alpine:latest
 ✔ Parsed image                                                                                                                                     sha256:5053b247d78b5e43b5543fec77c856ce70b8dc705d9f38336fa77736f25ff47c
 ✔ Cataloged packages              [16 packages]  
 ✔ Scanned for vulnerabilities     [2 vulnerabilities]  
   ├── 0 critical, 0 high, 0 medium, 0 low, 0 negligible (2 unknown)
   └── 2 fixed

❯ head test.json 
{
 "matches": [
  {
   "vulnerability": {
    "id": "CVE-2023-2975",
    "dataSource": "http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2023-2975",
    "namespace": "alpine:distro:alpine:3.18",
    "severity": "Unknown",
    "urls": [
     "http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2023-2975"

❯ head foo.csv 
"Package","Version Installed","Vulnerability ID","Severity"
"libcrypto3","3.1.1-r1","CVE-2023-2975","Unknown"
"libssl3","3.1.1-r1","CVE-2023-2975","Unknown"

Previously, the wrong path would get passed, and the template file would
get truncated.

Signed-off-by: Will Murphy <[email protected]>
Copy link
Contributor

@kzantow kzantow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@willmurphyscode willmurphyscode merged commit 43bcf30 into main Jul 17, 2023
@willmurphyscode willmurphyscode deleted the fix-1388 branch July 17, 2023 20:16
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 this pull request may close these issues.

grype v0.64.0 template zeroes the template content

2 participants