Sanitize makePubkeyHeader() calling semantics
authorPanu Matilainen <pmatilai@redhat.com>
Thu, 24 Nov 2011 09:28:15 +0000 (11:28 +0200)
committerPanu Matilainen <pmatilai@redhat.com>
Thu, 24 Nov 2011 09:28:15 +0000 (11:28 +0200)
- Create the header in makePubkeyHeader() as the name suggests,
  return the newly created header to caller on success.
- Move the installtime & -tid addition to the "install" part,
  makePubkeyHeader() only does the part that is specific to pubkey
  headers, again as the name suggests.
- No functional changes

lib/rpmts.c

index afee2cd..356b291 100644 (file)
@@ -351,8 +351,9 @@ static void loadKeyring(rpmts ts)
 }
 
 /* Build pubkey header. */
-static int makePubkeyHeader(rpmts ts, rpmPubkey key, Header h)
+static int makePubkeyHeader(rpmts ts, rpmPubkey key, Header * hdrp)
 {
+    Header h = headerNew();
     const char * afmt = "%{pubkeys:armor}";
     const char * group = "Public Keys";
     const char * license = "pubkey";
@@ -418,13 +419,11 @@ static int makePubkeyHeader(rpmts ts, rpmPubkey key, Header h)
     headerPutUint32(h, RPMTAG_BUILDTIME, &keytime, 1);
     headerPutString(h, RPMTAG_SOURCERPM, "(none)");
 
-    {   rpm_tid_t tid = rpmtsGetTid(ts);
-       headerPutUint32(h, RPMTAG_INSTALLTIME, &tid, 1);
-       headerPutUint32(h, RPMTAG_INSTALLTID, &tid, 1);
-    }
+    *hdrp = headerLink(h);
     rc = 0;
 
 exit:
+    headerFree(h);
     pgpFreeDig(dig);
     free(n);
     free(u);
@@ -439,7 +438,7 @@ exit:
 
 rpmRC rpmtsImportPubkey(const rpmts ts, const unsigned char * pkt, size_t pktlen)
 {
-    Header h = headerNew();
+    Header h = NULL;
     rpmRC rc = RPMRC_FAIL;             /* assume failure */
     rpmPubkey pubkey = NULL;
     rpmKeyring keyring = rpmtsGetKeyring(ts, 1);
@@ -453,9 +452,14 @@ rpmRC rpmtsImportPubkey(const rpmts ts, const unsigned char * pkt, size_t pktlen
 
     /* If we dont already have the key, make a persistent record of it */
     if (krc == 0) {
-       if (makePubkeyHeader(ts, pubkey, h) != 0) 
+       rpm_tid_t tid = rpmtsGetTid(ts);
+
+       if (makePubkeyHeader(ts, pubkey, &h) != 0) 
            goto exit;
 
+       headerPutUint32(h, RPMTAG_INSTALLTIME, &tid, 1);
+       headerPutUint32(h, RPMTAG_INSTALLTID, &tid, 1);
+
        /* Add header to database. */
        if (rpmtsOpenDB(ts, (O_RDWR|O_CREAT)))
            goto exit;