summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2020-11-23 15:00:02 +0200
committerPanu Matilainen <pmatilai@redhat.com>2020-12-10 13:28:07 +0200
commit614ee82ee9c10b79ed2a12ddec81efc56a30a712 (patch)
treee57d4d54e08cc2a147d87600b66f6c6b9579e1b8
parent13a5c0c8962613e4e2c2ac9932f4171a67bd545b (diff)
downloadrpm-614ee82ee9c10b79ed2a12ddec81efc56a30a712.tar.gz
Improve error handling in Python pubkey constructor
pkgParsePkts() only parses the PGP armor, the actual pubkey is only parsed as a part of rpmPubkeyNew() whose return we need to check for separately. Emit different messages in these cases. Thanks to @KOLANICH for pointing this out and initial patch. (cherry picked from commit ee5dd3ccb9fe084251f4c0195907a04a4bdc77e7)
-rw-r--r--python/rpmkeyring-py.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/python/rpmkeyring-py.c b/python/rpmkeyring-py.c
index 8968e0513..adf60e77e 100644
--- a/python/rpmkeyring-py.c
+++ b/python/rpmkeyring-py.c
@@ -27,10 +27,14 @@ static PyObject *rpmPubkey_new(PyTypeObject *subtype,
return NULL;
if (pgpParsePkts(PyBytes_AsString(key), &pkt, &pktlen) <= 0) {
- PyErr_SetString(PyExc_ValueError, "invalid pubkey");
+ PyErr_SetString(PyExc_ValueError, "invalid PGP armor");
return NULL;
}
pubkey = rpmPubkeyNew(pkt, pktlen);
+ if (pubkey == NULL) {
+ PyErr_SetString(PyExc_ValueError, "invalid pubkey");
+ return NULL;
+ }
return rpmPubkey_Wrap(subtype, pubkey);
}