blob: 044b4dd2a0955c3939d52421fb0ef76f0f5bb8d2 [file] [log] [blame]
Andrew Geissler595f6302022-01-24 19:11:47 +00001From 9a6871126f472feea057d5f803505ec8cc78f083 Mon Sep 17 00:00:00 2001
2From: Panu Matilainen <pmatilai@redhat.com>
3Date: Thu, 30 Sep 2021 09:56:20 +0300
4Subject: [PATCH 1/3] Refactor pgpDigParams construction to helper function
5
6No functional changes, just to reduce code duplication and needed by
7the following commits.
8
9CVE: CVE-2021-3521
10Upstream-Status: Backport [https://github.com/rpm-software-management/rpm/commit/9f03f42e2]
11
12Signed-off-by: Changqing Li <changqing.li@windriver.com>
13---
14 rpmio/rpmpgp.c | 13 +++++++++----
15 1 file changed, 9 insertions(+), 4 deletions(-)
16
17diff --git a/rpmio/rpmpgp.c b/rpmio/rpmpgp.c
18index d0688ebe9a..e472b5320f 100644
19--- a/rpmio/rpmpgp.c
20+++ b/rpmio/rpmpgp.c
21@@ -1041,6 +1041,13 @@ unsigned int pgpDigParamsAlgo(pgpDigParams digp, unsigned int algotype)
22 return algo;
23 }
24
25+static pgpDigParams pgpDigParamsNew(uint8_t tag)
26+{
27+ pgpDigParams digp = xcalloc(1, sizeof(*digp));
28+ digp->tag = tag;
29+ return digp;
30+}
31+
32 int pgpPrtParams(const uint8_t * pkts, size_t pktlen, unsigned int pkttype,
33 pgpDigParams * ret)
34 {
35@@ -1058,8 +1065,7 @@ int pgpPrtParams(const uint8_t * pkts, size_t pktlen, unsigned int pkttype,
36 if (pkttype && pkt.tag != pkttype) {
37 break;
38 } else {
39- digp = xcalloc(1, sizeof(*digp));
40- digp->tag = pkt.tag;
41+ digp = pgpDigParamsNew(pkt.tag);
42 }
43 }
44
45@@ -1105,8 +1111,7 @@ int pgpPrtParamsSubkeys(const uint8_t *pkts, size_t pktlen,
46 digps = xrealloc(digps, alloced * sizeof(*digps));
47 }
48
49- digps[count] = xcalloc(1, sizeof(**digps));
50- digps[count]->tag = PGPTAG_PUBLIC_SUBKEY;
51+ digps[count] = pgpDigParamsNew(PGPTAG_PUBLIC_SUBKEY);
52 /* Copy UID from main key to subkey */
53 digps[count]->userid = xstrdup(mainkey->userid);
54
55--
562.17.1
57