rpm-software-management / librepo

A library providing C and Python (libcURL like) API for downloading packages and linux repository metadata in rpm-md format
http://rpm-software-management.github.io/librepo/
GNU Lesser General Public License v2.1
74 stars 90 forks source link

The `lr gpg list_keys` function crashes if called on an empty keyring #276

Closed jrohel closed 1 year ago

jrohel commented 1 year ago

Error in line: for (guint i = 0; i < keys->len - 1; ++i) {

keys->len is unsigned. For empty keyring keys->len == 0. 0 - 1 is max value for unsigned type.

xiaoge1001 commented 1 year ago

@jrohel Hi, has this problem been solved? Is there any reproduction code?

jrohel commented 1 year ago

@xiaoge1001

has this problem been solved?

Yes, in this PR https://github.com/rpm-software-management/librepo/pull/277

Is there any reproduction code?

To reproduce the error, you need to call the lr gpg list_keys librepo API function where the home_dir parameter points to an empty directory. Or a directory containing an empty keyring.

The lr gpg list_keys function is used by the libdnf5 library and therefore the dnf5 application can be used to reproduce the error. The older library libdnf (and thus the application dnf, microdnf, PackageKit, ...) does not use this function yet, it assumes that librepo uses GpgME and accesses the keyring directly via the GpgME library. So they cannot be used for reproduction.

A simple reproducer:

jrohel commented 1 year ago

I am closing the issue. It is fixed by PR https://github.com/rpm-software-management/librepo/pull/277