Skip to content

Commit

Permalink
Implement CPE related problems (fixes #1039)
Browse files Browse the repository at this point in the history
  • Loading branch information
AMDmi3 committed May 17, 2020
1 parent da13b33 commit ac8a4d0
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
4 changes: 3 additions & 1 deletion sql.d/update/create_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ CREATE TYPE problem_type AS enum(
'homepage_discontinued_google',
'homepage_discontinued_codeplex',
'homepage_discontinued_gna',
'homepage_discontinued_cpan'
'homepage_discontinued_cpan',
'cpe_unreferenced',
'cpe_missing'
);

--------------------------------------------------------------------------------
Expand Down
59 changes: 59 additions & 0 deletions sql.d/update/update_problems.sql
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,65 @@ INNER JOIN packages USING(effname)
WHERE
homepage SIMILAR TO 'https?://search.cpan.org(/%%)?';

INSERT INTO problems(package_id, repo, name, effname, maintainer, "type", data)
SELECT DISTINCT
id,
repo,
visiblename,
effname,
unnest(CASE WHEN packages.maintainers = '{}' THEN '{null}' ELSE packages.maintainers END),
'cpe_unreferenced'::problem_type,
jsonb_build_object('vendor', cpe_vendor, 'product', cpe_product, 'suggestions',
(
SELECT jsonb_agg(DISTINCT jsonb_build_object('vendor', cpe_vendor, 'product', cpe_product))
FROM all_cpes
INNER JOIN vulnerable_versions USING (cpe_vendor, cpe_product)
WHERE all_cpes.effname = packages.effname
)
)
FROM changed_projects
INNER JOIN packages USING(effname)
WHERE
cpe_vendor IS NOT NULL AND
cpe_product IS NOT NULL AND
NOT EXISTS (
SELECT *
FROM vulnerable_versions
WHERE
vulnerable_versions.cpe_vendor = packages.cpe_vendor AND
vulnerable_versions.cpe_product = packages.cpe_product
);

INSERT INTO problems(package_id, repo, name, effname, maintainer, "type", data)
SELECT DISTINCT
id,
repo,
visiblename,
effname,
unnest(CASE WHEN packages.maintainers = '{}' THEN '{null}' ELSE packages.maintainers END),
'cpe_missing'::problem_type,
jsonb_build_object('suggestions',
(
SELECT jsonb_agg(DISTINCT jsonb_build_object('vendor', cpe_vendor, 'product', cpe_product))
FROM all_cpes
INNER JOIN vulnerable_versions USING (cpe_vendor, cpe_product)
WHERE all_cpes.effname = packages.effname
)
)
FROM changed_projects
INNER JOIN packages USING(effname)
WHERE
(
SELECT used_package_fields @> ARRAY['cpe_vendor'] FROM repositories WHERE repositories.name = packages.repo
) AND
cpe_vendor IS NULL AND
EXISTS (
SELECT *
FROM all_cpes
INNER JOIN vulnerable_versions USING (cpe_vendor, cpe_product)
WHERE all_cpes.effname = packages.effname
);

{% if analyze %}
ANALYZE problems;
{% endif %}

0 comments on commit ac8a4d0

Please sign in to comment.