Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite dpkginfo probe without using APT #2046

Merged
merged 1 commit into from
Nov 9, 2023

Conversation

0intro
Copy link
Contributor

@0intro 0intro commented Oct 24, 2023

This change rewrites the dpkginfo probe without using the APT library.

The dpkginfo now parses the list of installed package (/var/lib/dpkg/status) directly, instead of relying on the APT library.

This prevents loading the full list of packages in memory and various issues related to the use of the APT library.

The dpkginfo probe is now stateless and doesn't require init and fini functions. Also, the dpkginfo_get_by_name function can now be called from multiple threads without having to be protected by a lock.

The dependency on the APT library has been removed from OpenSCAP.

@evgenyz
Copy link
Contributor

evgenyz commented Oct 24, 2023

Are there any potential behaviour changes?

@0intro
Copy link
Contributor Author

0intro commented Oct 24, 2023

Are there any potential behaviour changes?

There shouldn't be. The new dpkginfo_get_by_name function should behave exactly like the former one.

One thing that the APT library did was to return only the packages installed for the current architecture. I don't think it really matters in practice, because the multiple architecture support is only used to install 32-bit libraries on 64-bits systems. Also, it didn't even work properly before, because the APT configuration (/etc/apt) was loaded from the root file system, instead of the directory specified by OSCAP_PROBE_ROOT (then the apt-config stuff was re-rooted on the right root directory to retrieve the package database).

@0intro 0intro requested a review from evgenyz November 6, 2023 10:50
else
snprintf(path, PATH_MAX, "/var/lib/dpkg/status");

f = fopen(path, "r");

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This argument to a file access function is derived from
user input (an environment variable)
and then passed to fopen(__filename).
Copy link
Contributor

@evgenyz evgenyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks!

But, I'd like to ask you to also update the docs, CI config and generic spec file (remove libapt dep) within the same PR. (See: https://github.com/search?q=repo%3AOpenSCAP%2Fopenscap%20apt-devel&type=code)

@0intro
Copy link
Contributor Author

0intro commented Nov 7, 2023

But, I'd like to ask you to also update the docs, CI config and generic spec file (remove libapt dep) within the same PR. (See: https://github.com/search?q=repo%3AOpenSCAP%2Fopenscap%20apt-devel&type=code)

I've just updated the docs, CI config and spec file. Let me know if I have missed anything.

@0intro 0intro requested a review from evgenyz November 7, 2023 11:10
@evgenyz
Copy link
Contributor

evgenyz commented Nov 7, 2023

Hold on a bit. Python 3.12 kicked us right in the fork.

@evgenyz
Copy link
Contributor

evgenyz commented Nov 7, 2023

And new kernel :(

@evgenyz
Copy link
Contributor

evgenyz commented Nov 8, 2023

Okay, we are good to go. Can you please rebase and have another go for CI?

Copy link
Contributor

@evgenyz evgenyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waiting for green CI.

This change rewrites the dpkginfo probe without using the
APT library.

The dpkginfo now parses the list of installed package
(/var/lib/dpkg/status) directly, instead of relying on
the APT library.

This prevents loading the full list of packages in memory
and various issues related to the use of the APT library.

The dpkginfo probe is now stateless and doesn't require
init and fini functions. Also, the dpkginfo_get_by_name
function can now be called from multiple threads without
having to be protected by a lock.

The dependency on the APT library has been removed from OpenSCAP.
@0intro
Copy link
Contributor Author

0intro commented Nov 8, 2023

It's green now (except CodeQL).

@evgenyz
Copy link
Contributor

evgenyz commented Nov 9, 2023

Thank you!

@evgenyz evgenyz merged commit 3f23bb8 into OpenSCAP:maint-1.3 Nov 9, 2023
18 of 19 checks passed
@evgenyz evgenyz added this to the 1.3.10 milestone Nov 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants