mirror of
https://github.com/aquasecurity/trivy.git
synced 2026-12-06 02:02:58 +00:00
fix: avoid panics on malformed dependency files and version-less Amazon Linux release (#10996)
Signed-off-by: Akshita <110122283+akshita317@users.noreply.github.com>
This commit is contained in:
1 parent
e97dfcc1bd
commit
ef28d95fea
14 files changed
+232
-15
No files matched your search
@@ -75,8 +75,14 @@ func (d *Dependencies) UnmarshalTOML(data any) error {
|
||||
// There are some formats:
|
||||
// e.g. `Flask == 1.1.4`, `Flask==1.1.4`, `Flask(>= 1.0.0)`, `pluggy[pre-commit,tox] (==0.13.1)`, etc.
|
||||
dep = strings.NewReplacer(">", " ", "<", " ", "=", " ", "(", " ", "[", " ").Replace(dep)
|
||||
fields := strings.Fields(dep)
|
||||
if len(fields) == 0 {
|
||||
// An entry that carries no name, e.g. `dependencies = [""]`.
|
||||
// cf. #10976
|
||||
continue
|
||||
}
|
||||
// Save only the name, normalized (PEP 503) to match the names from poetry.lock/pylock.toml.
|
||||
d.Set.Append(python.NormalizePkgName(strings.Fields(dep)[0], true))
|
||||
d.Set.Append(python.NormalizePkgName(fields[0], true))
|
||||
}
|
||||
default:
|
||||
return xerrors.Errorf("dependencies must be map, but got: %T", data)
|
||||
|
||||
@@ -120,6 +120,20 @@ func TestParser_Parse(t *testing.T) {
|
||||
},
|
||||
wantErr: assert.NoError,
|
||||
},
|
||||
{
|
||||
// A dependency entry that carries no name is skipped.
|
||||
// cf. #10976
|
||||
name: "empty dependency",
|
||||
file: "testdata/empty_dep.toml",
|
||||
want: pyproject.PyProject{
|
||||
Project: pyproject.Project{
|
||||
Dependencies: pyproject.Dependencies{
|
||||
Set: set.New[string]("flask"),
|
||||
},
|
||||
},
|
||||
},
|
||||
wantErr: assert.NoError,
|
||||
},
|
||||
{
|
||||
name: "sad path",
|
||||
file: "testdata/sad.toml",
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
[project]
|
||||
name = "example"
|
||||
version = "0.1.0"
|
||||
requires-python = ">=3.12"
|
||||
dependencies = [
|
||||
"",
|
||||
"flask == 1.1.4",
|
||||
]
|
||||
Reference in new issue
Block a user