[pacman-dev] [PATCH 1/2] libalpm: don't use alpm_pgpkey_t in import question

morganamilo morganamilo at archlinux.org
Thu Jun 3 20:25:04 UTC 2021


When constructing an import question we never really used a proper gpg
key. We just zero initialize the key, set the uid and fingerprint, and
sent that to the front end.

Instead lets just give the import question a uid and fingerprint field.
---
 lib/libalpm/alpm.h    |  6 ++++--
 lib/libalpm/signing.c | 10 +++-------
 src/pacman/callback.c |  6 +++---
 3 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index c4acc062..07833346 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -1082,8 +1082,10 @@ typedef struct _alpm_question_import_key_t {
 	alpm_question_type_t type;
 	/** Answer: whether or not to import key */
 	int import;
-	/** The key to import */
-	alpm_pgpkey_t *key;
+	/** UID of the key to import */
+	const char *uid;
+	/** Fingerprint the key to import */
+	const char *fingerprint;
 } alpm_question_import_key_t;
 
 /**
diff --git a/lib/libalpm/signing.c b/lib/libalpm/signing.c
index a7be3a1a..bba4e991 100644
--- a/lib/libalpm/signing.c
+++ b/lib/libalpm/signing.c
@@ -495,7 +495,7 @@ static int email_from_uid(const char *uid, char **email)
 int _alpm_key_import(alpm_handle_t *handle, const char *uid, const char *fpr)
 {
 	int ret = -1;
-	alpm_pgpkey_t fetch_key = {0};
+	alpm_pgpkey_t fetch_key;
 	char *email;
 
 	if(_alpm_access(handle, handle->gpgdir, "pubring.gpg", W_OK)) {
@@ -504,19 +504,15 @@ int _alpm_key_import(alpm_handle_t *handle, const char *uid, const char *fpr)
 		return -1;
 	}
 
-	STRDUP(fetch_key.uid, uid, return -1);
-	STRDUP(fetch_key.fingerprint, fpr, free(fetch_key.uid); return -1);
 
 	alpm_question_import_key_t question = {
 				.type = ALPM_QUESTION_IMPORT_KEY,
 				.import = 0,
-				.key = &fetch_key
+				.uid = uid,
+				.fingerprint = fpr
 			};
 	QUESTION(handle, &question);
 
-	free(fetch_key.uid);
-	free(fetch_key.fingerprint);
-
 	if(question.import) {
 		/* Try to import the key from a WKD first */
 		if(email_from_uid(uid, &email) == 0) {
diff --git a/src/pacman/callback.c b/src/pacman/callback.c
index 99ad716e..c9fe4b2e 100644
--- a/src/pacman/callback.c
+++ b/src/pacman/callback.c
@@ -541,12 +541,12 @@ void cb_question(void *ctx, alpm_question_t *question)
 			{
 				alpm_question_import_key_t *q = &question->import_key;
 				/* the uid is unknown with db signatures */
-				if (q->key->uid == NULL) {
+				if (q->uid == NULL) {
 					q->import = yesno(_("Import PGP key %s?"),
-							q->key->fingerprint);
+							q->fingerprint);
 				} else {
 					q->import = yesno(_("Import PGP key %s, \"%s\"?"),
-							q->key->fingerprint, q->key->uid);
+							q->fingerprint, q->uid);
 				}
 			}
 			break;
-- 
2.31.1


More information about the pacman-dev mailing list