Skip to content

Commit

Permalink
Lock key during rpmGetSubkeys()
Browse files Browse the repository at this point in the history
This should be thread save as it still is in the public API. The
internal use would be fine otherwise. So the lock can be removed if this
gets made internal only.

Resolves: rpm-software-management#3351
  • Loading branch information
ffesti committed Oct 9, 2024
1 parent a45134e commit 96d2d24
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions rpmio/rpmkeyring.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,21 @@ rpmPubkey *rpmGetSubkeys(rpmPubkey primarykey, int *count)
int pgpsubkeysCount = 0;
int i;

if (primarykey && !pgpPrtParamsSubkeys(primarykey->pkt.data(), primarykey->pkt.size(),
primarykey->pgpkey, &pgpsubkeys, &pgpsubkeysCount)) {
/* Returned to C, can't use new */
subkeys = (rpmPubkey *)xmalloc(pgpsubkeysCount * sizeof(*subkeys));
for (i = 0; i < pgpsubkeysCount; i++) {
subkeys[i] = rpmPubkeyNewSubkey(primarykey, pgpsubkeys[i]);
primarykey = pubkeyLink(primarykey);
if (primarykey) {

rdlock lock(primarykey->mutex);

if (!pgpPrtParamsSubkeys(
primarykey->pkt.data(), primarykey->pkt.size(),
primarykey->pgpkey, &pgpsubkeys, &pgpsubkeysCount)) {
/* Returned to C, can't use new */
subkeys = (rpmPubkey *)xmalloc(pgpsubkeysCount * sizeof(*subkeys));
for (i = 0; i < pgpsubkeysCount; i++) {
subkeys[i] = rpmPubkeyNewSubkey(primarykey, pgpsubkeys[i]);
primarykey = pubkeyLink(primarykey);
}
free(pgpsubkeys);
}
free(pgpsubkeys);
}
*count = pgpsubkeysCount;

Expand Down

0 comments on commit 96d2d24

Please sign in to comment.