diff options
author | jbj <devnull@localhost> | 2003-04-21 22:31:28 +0000 |
---|---|---|
committer | jbj <devnull@localhost> | 2003-04-21 22:31:28 +0000 |
commit | 3f50b8fe7e1f94b9fa8fbec915f74510841ddcd2 (patch) | |
tree | 4fdd5197d84dd7dc2303462a7129a2fc092f9b62 | |
parent | 96142f1201ecfd4b867a40b2ba733bdf7269ef79 (diff) | |
download | librpm-tizen-3f50b8fe7e1f94b9fa8fbec915f74510841ddcd2.tar.gz librpm-tizen-3f50b8fe7e1f94b9fa8fbec915f74510841ddcd2.tar.bz2 librpm-tizen-3f50b8fe7e1f94b9fa8fbec915f74510841ddcd2.zip |
Don't segfault if given ascii armored rather than binary pubkey packets.
CVS patchset: 6765
CVS date: 2003/04/21 22:31:28
-rw-r--r-- | lib/rpmchecksig.c | 21 | ||||
-rw-r--r-- | lib/rpmcli.h | 4 |
2 files changed, 17 insertions, 8 deletions
diff --git a/lib/rpmchecksig.c b/lib/rpmchecksig.c index bdd4e1827..92ccf0cd0 100644 --- a/lib/rpmchecksig.c +++ b/lib/rpmchecksig.c @@ -402,8 +402,10 @@ exit: return res; } -int rpmcliImportPubkey(const rpmts ts, const unsigned char * pkt, ssize_t pktlen) +rpmRC rpmcliImportPubkey(const rpmts ts, const unsigned char * pkt, ssize_t pktlen) { + static unsigned char zeros[] = + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; const char * afmt = "%{pubkeys:armor}"; const char * group = "Public Keys"; const char * license = "pubkey"; @@ -420,14 +422,14 @@ int rpmcliImportPubkey(const rpmts ts, const unsigned char * pkt, ssize_t pktlen const char * r = NULL; const char * evr = NULL; Header h = NULL; - int rc = 1; /* assume failure */ + rpmRC rc = RPMRC_FAIL; /* assume failure */ char * t; int xx; if (pkt == NULL || pktlen <= 0) - return -1; + return RPMRC_FAIL; if (rpmtsOpenDB(ts, (O_RDWR|O_CREAT))) - return -1; + return RPMRC_FAIL; if ((enc = b64encode(pkt, pktlen)) == NULL) goto exit; @@ -438,6 +440,11 @@ int rpmcliImportPubkey(const rpmts ts, const unsigned char * pkt, ssize_t pktlen (void) pgpPrtPkts(pkt, pktlen, dig, 0); pubp = &dig->pubkey; + if (!memcmp(pubp->signid, zeros, sizeof(pubp->signid)) + || !memcmp(pubp->time, zeros, sizeof(pubp->time)) + || pubp->userid == NULL) + goto exit; + /*@-boundswrite@*/ v = t = xmalloc(16+1); t = stpcpy(t, pgpHexStr(pubp->signid, sizeof(pubp->signid))); @@ -510,9 +517,10 @@ int rpmcliImportPubkey(const rpmts ts, const unsigned char * pkt, ssize_t pktlen #endif /* Add header to database. */ - rc = rpmdbAdd(rpmtsGetRdb(ts), rpmtsGetTid(ts), h, NULL, NULL); + xx = rpmdbAdd(rpmtsGetRdb(ts), rpmtsGetTid(ts), h, NULL, NULL); if (xx != 0) goto exit; + rc = RPMRC_OK; exit: /* Clean up. */ @@ -549,6 +557,7 @@ static int rpmcliImportPubkeys(const rpmts ts, const unsigned char * pkt = NULL; ssize_t pktlen = 0; int res = 0; + rpmRC rpmrc; int rc; if (argv == NULL) return res; @@ -574,7 +583,7 @@ rpmtsClean(ts); } /* Import pubkey packet(s). */ - if ((rc = rpmcliImportPubkey(ts, pkt, pktlen)) != 0) { + if ((rpmrc = rpmcliImportPubkey(ts, pkt, pktlen)) != RPMRC_OK) { rpmError(RPMERR_IMPORT, _("%s: import failed.\n"), fn); res++; continue; diff --git a/lib/rpmcli.h b/lib/rpmcli.h index 707a0aa60..8f9fabd6d 100644 --- a/lib/rpmcli.h +++ b/lib/rpmcli.h @@ -727,9 +727,9 @@ extern struct poptOption rpmDatabasePoptTable[]; * @param ts transaction set * @param pkt pgp pubkey packet(s) * @param pktlen pgp pubkey length - * @return 0 on success + * @return RPMRC_OK/RPMRC_FAIL */ -int rpmcliImportPubkey(const rpmts ts, +rpmRC rpmcliImportPubkey(const rpmts ts, const unsigned char * pkt, ssize_t pktlen) /*@globals RPMVERSION, rpmGlobalMacroContext, fileSystem, internalState @*/ |