fix: only report genuinely-installed packages in is_pkg_installed#326
Open
nicodarge wants to merge 1 commit into
Open
fix: only report genuinely-installed packages in is_pkg_installed#326nicodarge wants to merge 1 commit into
nicodarge wants to merge 1 commit into
Conversation
is_pkg_installed matched '^Status: install ', which keys off the dpkg
*desired-action* field rather than the actual package status. A package
that is not installed but still carries an "install" selection (states
such as "install ok not-installed" or "install ok config-files") was
reported as installed.
This produced false positives in every package-based check: on hosts
with such residual selections, disable_http_server (2.2.10) and
disable_http_proxy (2.2.13) crit on nginx/squid that are not actually
installed.
Query the real status field via 'dpkg-query -W -f=${db:Status-Status}'
and match installed/triggers-awaited/triggers-pending (all functionally
installed). This is immune to the desired-action field, so a held package
("hold ok installed") is still reported as installed while residual
selections are not.
The same buggy pattern is also replaced in the auditd test scenarios.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
is_pkg_installed()reports packages as installed when they are not, because it keys off the dpkg desired-action field instead of the actual package status.Root cause
The
Status:line is<desired-action> <error> <status>. The pattern^Status: installonly checks the desired-action field, so it also matches packages that are not installed but still carry aninstallselection, e.g.:install ok not-installed(a leftover selection, e.g. afterdpkg --set-selections)install ok config-filesinstall ok half-installedImpact
Every package-based check is affected. In practice this shows up on
disable_http_server(2.2.10) anddisable_http_proxy(2.2.13): a host that once hadnginx/squidand still carries a residualinstallselection gets a falsecriteven though the package is gone.Reproduction:
Fix
Query the real status field and match only the functionally-installed states:
This is independent of the desired-action field, so:
installselections on absent packages are no longer reported as installed;hold ok installed) is still correctly reported as installed;triggers-awaited/triggers-pending(functionally installed) are matched.The same inline pattern was duplicated in the
auditdtest scenarios (used to decide whether to installauditdbefore the test) and is updated to the same idiom.How tested
shellcheckandshfmt -i 4clean on all changed files.auditdanddisable_http_*scenarios run green.dpkg-query -W -f='${db:Status-Status}'is available (dpkg ≥ 1.17).