[Rpm-maint] [rpm-software-management/rpm] Handle subkeys in rpmKeyringModify (PR #3403)

Panu Matilainen notifications at github.com
Thu Oct 24 12:57:21 UTC 2024


@pmatilai commented on this pull request.



> @@ -133,16 +133,32 @@ int rpmKeyringModify(rpmKeyring keyring, rpmPubkey key, rpmKeyringModifyMode mod
 	if (item->second->fp == key->fp)
 	    break;
     }
-    if (item != range.second && mode == RPMKEYRING_DELETE) {
+    if (item != range.second && (mode == RPMKEYRING_DELETE || mode == RPMKEYRING_REPLACE)) {
+	/* remove sub keys */
+	for (auto it = keyring->keys.begin(); it != keyring->keys.end();) {
+	    if (it->second->primarykey == item->second) {
+		rpmPubkeyFree(it->second);
+		it = keyring->keys.erase(it);
+	    } else {
+		++it;

Don't use a for-loop when you mess with the "counter" from inside, I'm not sure that's defined behavior at all. And even if the compiler handles it, the reader wont expect it. A while-loop alarts the reader to some manual loop management ahead, see eg freeArgs() in macros.c

-- 
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/pull/3403#pullrequestreview-2392414793
You are receiving this because you are subscribed to this thread.

Message ID: <rpm-software-management/rpm/pull/3403/review/2392414793 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rpm.org/pipermail/rpm-maint/attachments/20241024/3c76e3f3/attachment.html>


More information about the Rpm-maint mailing list