mirror of
https://github.com/anchore/syft.git
synced 2026-10-30 14:02:26 +01:00
`ProcessPathErrors` cut the `path="..."` it pulled out of an error at the first `!/` and built nested coordinates from it, so a host file with `!/` in its name was reported as a file inside an archive. - paths from error text are taken as plain real paths again, as on main - the php extension reader already has the location in hand, so it records the unknown against that instead of re-parsing the error (this is the one caller that could see a nested path). It also no longer defers `Close` on a nil reader when the read fails Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
36 lines
1001 B
Go
36 lines
1001 B
Go
package unknown
|
|
|
|
import (
|
|
"regexp"
|
|
|
|
"github.com/anchore/syft/internal/log"
|
|
"github.com/anchore/syft/syft/file"
|
|
)
|
|
|
|
var pathErrorRegex = regexp.MustCompile(`.*path="([^"]+)".*`)
|
|
|
|
// ProcessPathErrors replaces "path" errors returned from the file.Resolver into unknowns,
|
|
// and warn logs non-unknown errors, returning only the unknown errors
|
|
func ProcessPathErrors(err error) error {
|
|
if err == nil {
|
|
return nil
|
|
}
|
|
errText := err.Error()
|
|
if pathErrorRegex.MatchString(errText) {
|
|
foundPath := pathErrorRegex.ReplaceAllString(err.Error(), "$1")
|
|
if foundPath != "" {
|
|
// a path in an error text is taken as is: nesting is never inferred from "!/" in it, since a real
|
|
// path can hold one too. A caller with the location in hand should use New instead
|
|
return New(file.NewLocation(foundPath), err)
|
|
}
|
|
}
|
|
unknowns, remainingErrors := ExtractCoordinateErrors(err)
|
|
log.Debug(remainingErrors)
|
|
|
|
var out []error
|
|
for _, u := range unknowns {
|
|
out = append(out, &u)
|
|
}
|
|
return Join(out...)
|
|
}
|