github.com/google/osv-scalibr@v0.4.1/enricher/govulncheck/source/internal/result.go (about) 1 // Copyright 2025 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Derived from https://github.com/golang/vuln/blob/267a472bf377fa105988693c2a597d2b8de36ad8/internal/govulncheck/result.go 16 // 17 // Copyright 2023 The Go Authors. All rights reserved. 18 // Use of this source code is governed by a BSD-style 19 // license that can be found in the LICENSE file. 20 21 // Package internal contains govulncheck models 22 package internal 23 24 // Message is an entry in the output stream. It will always have exactly one 25 // field filled in. 26 type Message struct { 27 Finding *Finding `json:"finding,omitempty"` 28 29 // The Config, Progress, and OSV fields from the JSON output are removed, since they 30 // are not used. 31 } 32 33 // Finding represents a single finding. 34 type Finding struct { 35 // OSV is the id of the detected vulnerability. 36 OSV string `json:"osv,omitempty"` 37 38 // FixedVersion is the module version where the vulnerability was 39 // fixed. This is empty if a fix is not available. 40 // 41 // If there are multiple fixed versions in the OSV report, this will 42 // be the fixed version in the latest range event for the OSV report. 43 // 44 // For example, if the range events are 45 // {introduced: 0, fixed: 1.0.0} and {introduced: 1.1.0}, the fixed version 46 // will be empty. 47 // 48 // For the stdlib, we will show the fixed version closest to the 49 // Go version that is used. For example, if a fix is available in 1.17.5 and 50 // 1.18.5, and the GOVERSION is 1.17.3, 1.17.5 will be returned as the 51 // fixed version. 52 FixedVersion string `json:"fixed_version,omitempty"` 53 54 // Trace contains an entry for each frame in the trace. 55 // 56 // Frames are sorted starting from the imported vulnerable symbol 57 // until the entry point. The first frame in Frames should match 58 // Symbol. 59 // 60 // In binary mode, trace will contain a single-frame with no position 61 // information. 62 // 63 // When a package is imported but no vulnerable symbol is called, the trace 64 // will contain a single-frame with no symbol or position information. 65 Trace []*Frame `json:"trace,omitempty"` 66 } 67 68 // Frame represents an entry in a finding trace. 69 type Frame struct { 70 // Module is the module path of the module containing this symbol. 71 // 72 // Importable packages in the standard library will have the path "stdlib". 73 Module string `json:"module"` 74 75 // Version is the module version from the build graph. 76 Version string `json:"version,omitempty"` 77 78 // Package is the import path. 79 Package string `json:"package,omitempty"` 80 81 // Function is the function name. 82 Function string `json:"function,omitempty"` 83 84 // Receiver is the receiver type if the called symbol is a method. 85 // 86 // The client can create the final symbol name by 87 // prepending Receiver to FuncName. 88 Receiver string `json:"receiver,omitempty"` 89 90 // Position describes an arbitrary source position 91 // including the file, line, and column location. 92 // A Position is valid if the line number is > 0. 93 Position *Position `json:"position,omitempty"` 94 } 95 96 // Position is a copy of token.Position used to marshal/unmarshal 97 // JSON correctly. 98 type Position struct { 99 Filename string `json:"filename,omitempty"` // filename, if any 100 Offset int `json:"offset"` // offset, starting at 0 101 Line int `json:"line"` // line number, starting at 1 102 Column int `json:"column"` // column number, starting at 1 (byte count) 103 }