mirror of
https://github.com/anchore/syft.git
synced 2026-10-15 07:37:20 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
727b84ce0d | ||
|
|
85ac5bcbf8 | ||
|
|
3d8c16649d | ||
|
|
ecbfbe6896 |
@@ -104,7 +104,8 @@ syft packages <image> -o <format>
|
||||
Where the `formats` available are:
|
||||
- `json`: Use this to get as much information out of Syft as possible!
|
||||
- `text`: A row-oriented, human-and-machine-friendly output.
|
||||
- `cyclonedx`: A XML report conforming to the [CycloneDX 1.2 specification](https://cyclonedx.org/specification/overview/).
|
||||
- `cyclonedx`: A XML report conforming to the [CycloneDX 1.3 specification](https://cyclonedx.org/specification/overview/).
|
||||
- `cyclonedx-json`: A JSON report conforming to the [CycloneDX 1.3 specification](https://cyclonedx.org/specification/overview/).
|
||||
- `spdx`: A tag-value formatted report conforming to the [SPDX 2.2 specification](https://spdx.github.io/spdx-spec/).
|
||||
- `spdx-json`: A JSON report conforming to the [SPDX 2.2 JSON Schema](https://github.com/spdx/spdx-spec/blob/v2.2/schemas/spdx-schema.json).
|
||||
- `table`: A columnar summary (default).
|
||||
|
||||
+5
-3
@@ -1,7 +1,5 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
# Code generated by godownloader on 2020-08-10T20:55:46Z.
|
||||
#
|
||||
|
||||
usage() {
|
||||
this=$1
|
||||
@@ -23,7 +21,7 @@ EOF
|
||||
}
|
||||
|
||||
parse_args() {
|
||||
#BINDIR is ./bin unless set be ENV
|
||||
# BINDIR is ./bin unless set be ENV
|
||||
# over-ridden by flag below
|
||||
|
||||
BINDIR=${BINDIR:-./bin}
|
||||
@@ -67,6 +65,7 @@ execute() {
|
||||
}
|
||||
get_binaries() {
|
||||
case "$PLATFORM" in
|
||||
darwin/arm64) BINARIES="syft" ;;
|
||||
darwin/amd64) BINARIES="syft" ;;
|
||||
linux/amd64) BINARIES="syft" ;;
|
||||
windows/amd64) BINARIES="syft" ;;
|
||||
@@ -97,6 +96,9 @@ adjust_format() {
|
||||
darwin) FORMAT=dmg ;;
|
||||
windows) FORMAT=zip ;;
|
||||
esac
|
||||
case "${PLATFORM}" in
|
||||
darwin/arm64) FORMAT=zip ;;
|
||||
esac
|
||||
true
|
||||
}
|
||||
adjust_os() {
|
||||
|
||||
@@ -19,48 +19,66 @@ const manifestGlob = "/META-INF/MANIFEST.MF"
|
||||
// For more information: https://docs.oracle.com/en/java/javase/11/docs/specs/jar/jar.html#jar-manifest
|
||||
func parseJavaManifest(path string, reader io.Reader) (*pkg.JavaManifest, error) {
|
||||
var manifest pkg.JavaManifest
|
||||
sections := []map[string]string{
|
||||
make(map[string]string),
|
||||
var sections []map[string]string
|
||||
|
||||
currentSection := func() int {
|
||||
return len(sections) - 1
|
||||
}
|
||||
currentSection := 0
|
||||
scanner := bufio.NewScanner(reader)
|
||||
|
||||
var lastKey string
|
||||
scanner := bufio.NewScanner(reader)
|
||||
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
|
||||
// empty lines denote section separators
|
||||
if strings.TrimSpace(line) == "" {
|
||||
currentSection++
|
||||
// we don't want to allocate a new section map that wont necessarily be used, do that once there is
|
||||
// we don't want to allocate a new section map that won't necessarily be used, do that once there is
|
||||
// a non-empty line to process
|
||||
|
||||
// do not process line continuations after this
|
||||
lastKey = ""
|
||||
|
||||
continue
|
||||
} else if currentSection >= len(sections) {
|
||||
sections = append(sections, make(map[string]string))
|
||||
}
|
||||
|
||||
if line[0] == ' ' {
|
||||
// this is a continuation
|
||||
|
||||
if lastKey == "" {
|
||||
return nil, fmt.Errorf("found continuation with no previous key (%s)", line)
|
||||
}
|
||||
sections[currentSection][lastKey] += strings.TrimSpace(line)
|
||||
} else {
|
||||
// this is a new key-value pair
|
||||
idx := strings.Index(line, ":")
|
||||
if idx == -1 {
|
||||
return nil, fmt.Errorf("unable to split java manifest key-value pairs: %q", line)
|
||||
log.Warnf("java manifest %q: found continuation with no previous key: %q", path, line)
|
||||
continue
|
||||
}
|
||||
|
||||
key := strings.TrimSpace(line[0:idx])
|
||||
value := strings.TrimSpace(line[idx+1:])
|
||||
sections[currentSection][key] = value
|
||||
sections[currentSection()][lastKey] += strings.TrimSpace(line)
|
||||
|
||||
// keep track of key for potential future continuations
|
||||
lastKey = key
|
||||
continue
|
||||
}
|
||||
|
||||
// this is a new key-value pair
|
||||
idx := strings.Index(line, ":")
|
||||
if idx == -1 {
|
||||
log.Warnf("java manifest %q: unable to split java manifest key-value pairs: %q", path, line)
|
||||
continue
|
||||
}
|
||||
|
||||
key := strings.TrimSpace(line[0:idx])
|
||||
value := strings.TrimSpace(line[idx+1:])
|
||||
|
||||
if key == "" {
|
||||
// don't attempt to add new keys or sections unless there is a non-empty key
|
||||
continue
|
||||
}
|
||||
|
||||
if lastKey == "" {
|
||||
// we're entering a new section
|
||||
sections = append(sections, make(map[string]string))
|
||||
}
|
||||
|
||||
sections[currentSection()][key] = value
|
||||
|
||||
// keep track of key for potential future continuations
|
||||
lastKey = key
|
||||
}
|
||||
|
||||
if err := scanner.Err(); err != nil {
|
||||
@@ -75,7 +93,7 @@ func parseJavaManifest(path string, reader io.Reader) (*pkg.JavaManifest, error)
|
||||
name, ok := s["Name"]
|
||||
if !ok {
|
||||
// per the manifest spec (https://docs.oracle.com/en/java/javase/11/docs/specs/jar/jar.html#jar-manifest)
|
||||
// this should never happen. If it does we want to know about it, but not necessarily stop
|
||||
// this should never happen. If it does, we want to know about it, but not necessarily stop
|
||||
// cataloging entirely... for this reason we only log.
|
||||
log.Warnf("java manifest section found without a name: %s", path)
|
||||
name = strconv.Itoa(i)
|
||||
|
||||
@@ -58,6 +58,30 @@ func TestParseJavaManifest(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
fixture: "test-fixtures/manifest/extra-empty-lines",
|
||||
expected: pkg.JavaManifest{
|
||||
Main: map[string]string{
|
||||
"Manifest-Version": "1.0",
|
||||
"Archiver-Version": "Plexus Archiver",
|
||||
"Created-By": "Apache Maven 3.6.3",
|
||||
},
|
||||
NamedSections: map[string]map[string]string{
|
||||
"thing-1": {
|
||||
"Built-By": "?",
|
||||
},
|
||||
"thing-2": {
|
||||
"Built-By": "someone!",
|
||||
},
|
||||
"2": {
|
||||
"Other": "things",
|
||||
},
|
||||
"3": {
|
||||
"Last": "item",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
fixture: "test-fixtures/manifest/continuation",
|
||||
expected: pkg.JavaManifest{
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
Manifest-Version: 1.0
|
||||
Archiver-Version: Plexus Archiver
|
||||
Created-By: Apache Maven 3.6.3
|
||||
|
||||
|
||||
Name: thing-1
|
||||
Built-By: ?
|
||||
|
||||
.
|
||||
|
||||
Name: thing-2
|
||||
Built-By: someone!
|
||||
|
||||
|
||||
:
|
||||
|
||||
Other: things
|
||||
junk
|
||||
|
||||
:
|
||||
|
||||
Last: item
|
||||
Reference in New Issue
Block a user