From b4c604e75c8550c5e63d5a6781e03ef40b78cca4 Mon Sep 17 00:00:00 2001 From: jbj Date: Tue, 7 May 2002 01:07:41 +0000 Subject: [PATCH] - plug most install mode leaks. CVS patchset: 5424 CVS date: 2002/05/07 01:07:41 --- CHANGES | 1 + lib/depends.c | 27 +++++++++++++++++++++++---- lib/problems.c | 1 + lib/rpmfi.c | 8 +++++++- lib/rpmts.c | 9 +++++++++ lib/rpmts.h | 6 ++++++ lib/signature.c | 31 +++++++++++++++---------------- lib/transaction.c | 5 +++-- rpm.spec.in | 3 ++- rpmdb/header.c | 8 ++++---- rpmdb/header_internal.h | 1 + rpmio/rpmpgp.c | 14 ++++++++++++++ 12 files changed, 86 insertions(+), 28 deletions(-) diff --git a/CHANGES b/CHANGES index 21ee452..98579bc 100644 --- a/CHANGES +++ b/CHANGES @@ -111,6 +111,7 @@ - rework most of rpmdb.c prepatory to implementing duplicates. - fix: 2 memory leaks in headerSprintf. - fix: db mire's access out-of-bounds memory. + - plug most install mode leaks. 4.0.3 -> 4.0.4: - solaris: translate i86pc to i386 (#57182). diff --git a/lib/depends.c b/lib/depends.c index 334e505..01bbb74 100644 --- a/lib/depends.c +++ b/lib/depends.c @@ -743,11 +743,29 @@ static struct badDeps_s { { NULL, NULL } }; #else +/*@unchecked@*/ +static int badDepsInitialized = 0; + /*@unchecked@*/ /*@only@*/ /*@null@*/ static struct badDeps_s * badDeps = NULL; #endif /** + */ +static void freeBadDeps(void) + /*@globals badDeps, badDepsInitialized @*/ + /*@modifies badDeps, badDepsInitialized @*/ +{ + if (badDeps) { + struct badDeps_s * bdp; + for (bdp = badDeps; bdp->pname != NULL && bdp->qname != NULL; bdp++) + bdp->pname = _free(bdp->pname); + badDeps = _free(badDeps); + } + badDepsInitialized = 0; +} + +/** * Check for dependency relations to be ignored. * * @param p successor element (i.e. with Requires: ) @@ -756,13 +774,13 @@ static struct badDeps_s * badDeps = NULL; */ static int ignoreDep(const transactionElement p, const transactionElement q) - /*@*/ + /*@globals badDeps, badDepsInitialized @*/ + /*@modifies badDeps, badDepsInitialized @*/ { struct badDeps_s * bdp; - static int _initialized = 0; /*@-globs -mods@*/ - if (!_initialized) { + if (!badDepsInitialized) { char * s = rpmExpand("%{?_dependency_whiteout}", NULL); const char ** av = NULL; int ac = 0; @@ -794,7 +812,7 @@ static int ignoreDep(const transactionElement p, } av = _free(av); s = _free(s); - _initialized++; + badDepsInitialized++; } /*@=globs =mods@*/ @@ -1585,6 +1603,7 @@ assert(newOrderCount == ts->orderCount); #else rpmtransClean(ts); #endif + freeBadDeps(); return 0; } diff --git a/lib/problems.c b/lib/problems.c index 817dce4..a382757 100644 --- a/lib/problems.c +++ b/lib/problems.c @@ -66,6 +66,7 @@ rpmProblemSet rpmProblemSetFree(rpmProblemSet ps) p->altNEVR = _free(p->altNEVR); p->str1 = _free(p->str1); } + ps->probs = _free(ps->probs); } (void) rpmpsUnlink(ps, "destroy"); /*@-refcounttrans -usereleased@*/ diff --git a/lib/rpmfi.c b/lib/rpmfi.c index 41df31f..db2d0c8 100644 --- a/lib/rpmfi.c +++ b/lib/rpmfi.c @@ -979,8 +979,10 @@ TFI_t fiNew(rpmTransactionSet ts, TFI_t fi, fi->action = FA_UNKNOWN; fi->flags = 0; - if (fi->actions == NULL) + +if (fi->actions == NULL) fi->actions = xcalloc(fi->fc, sizeof(*fi->actions)); + fi->keep_header = (scareMem ? 1 : 0); /* XXX TR_REMOVED needs CPIO_MAP_{ABSOLUTE,ADDDOT} CPIO_ALL_HARDLINKS */ @@ -991,6 +993,7 @@ TFI_t fiNew(rpmTransactionSet ts, TFI_t fi, xx = hge(h, RPMTAG_FILELANGS, NULL, (void **) &fi->flangs, NULL); xx = hge(h, RPMTAG_FILEMD5S, NULL, (void **) &fi->fmd5s, NULL); + t = xmalloc(fi->fc * 16); fi->md5s = t; for (i = 0; i < fi->fc; i++) { @@ -1011,6 +1014,7 @@ TFI_t fiNew(rpmTransactionSet ts, TFI_t fi, /* XXX TR_REMOVED doesn;t need fmtimes or frdevs */ xx = hge(h, RPMTAG_FILEMTIMES, NULL, (void **) &fi->fmtimes, NULL); xx = hge(h, RPMTAG_FILERDEVS, NULL, (void **) &fi->frdevs, NULL); + fi->replacedSizes = xcalloc(fi->fc, sizeof(*fi->replacedSizes)); xx = hge(h, RPMTAG_FILEUSERNAME, NULL, (void **) &fi->fuser, NULL); @@ -1022,6 +1026,8 @@ TFI_t fiNew(rpmTransactionSet ts, TFI_t fi, if (fi != NULL) if (fi->te != NULL && fi->te->type == TR_ADDED) { Header foo; +/* XXX DYING */ +if (fi->actions == NULL) fi->actions = xcalloc(fi->fc, sizeof(*fi->actions)); /*@-compdef@*/ /* FIX: fi-md5s undefined */ foo = relocateFileList(ts, fi, h, fi->actions); diff --git a/lib/rpmts.c b/lib/rpmts.c index ec4b441..9f22248 100644 --- a/lib/rpmts.c +++ b/lib/rpmts.c @@ -309,6 +309,7 @@ void rpmtransClean(rpmTransactionSet ts) if (ts->sig != NULL) ts->sig = headerFreeData(ts->sig, ts->sigtype); + if (ts->dig != NULL) ts->dig = pgpFreeDig(ts->dig); } @@ -353,6 +354,11 @@ rpmTransactionSet rpmtransFree(rpmTransactionSet ts) ts->order = _free(ts->order); /*@=type =voidabstract @*/ + if (ts->pkpkt != NULL) + ts->pkpkt = _free(ts->pkpkt); + ts->pkpktlen = 0; + memset(ts->pksignid, 0, sizeof(ts->pksignid)); + /*@-nullstate@*/ /* FIX: partial annotations */ rpmtransClean(ts); /*@=nullstate@*/ @@ -428,6 +434,9 @@ rpmTransactionSet rpmtransCreateSet(rpmdb db, const char * rootDir) ts->probs = NULL; ts->sig = NULL; + ts->pkpkt = NULL; + ts->pkpktlen = 0; + memset(ts->pksignid, 0, sizeof(ts->pksignid)); ts->dig = NULL; ts->nrefs = 0; diff --git a/lib/rpmts.h b/lib/rpmts.h index 4dec24b..2c8696a 100644 --- a/lib/rpmts.h +++ b/lib/rpmts.h @@ -102,6 +102,12 @@ struct rpmTransactionSet_s { int_32 sigtype; /*!< Current package signature data type. */ /*@null@*/ const void * sig; /*!< Current package signature. */ int_32 siglen; /*!< Current package signature length. */ + +/*@only@*/ /*@null@*/ + const unsigned char * pkpkt;/*!< Current pubkey packet. */ + size_t pkpktlen; /*!< Current pubkey packet length. */ + unsigned char pksignid[8]; /*!< Current pubkey fingerprint. */ + /*@null@*/ struct pgpDig_s * dig; /*!< Current signature/pubkey parametrs. */ diff --git a/lib/signature.c b/lib/signature.c index 491b337..f6754b8 100644 --- a/lib/signature.c +++ b/lib/signature.c @@ -926,9 +926,6 @@ rpmtsFindPubkey(rpmTransactionSet ts) { struct pgpDigParams_s * sigp = NULL; rpmVerifySignatureReturn res; - /*@unchecked@*/ /*@only@*/ static const byte * pkpkt = NULL; - /*@unchecked@*/ static size_t pkpktlen = 0; - /*@unchecked@*/ static byte pksignid[8]; int xx; if (ts->sig == NULL || ts->dig == NULL) { @@ -937,14 +934,16 @@ rpmtsFindPubkey(rpmTransactionSet ts) } sigp = &ts->dig->signature; - if (pkpkt == NULL || memcmp(sigp->signid, pksignid, sizeof(pksignid))) { + if (ts->pkpkt == NULL + || memcmp(sigp->signid, ts->pksignid, sizeof(ts->pksignid))) + { int ix = -1; rpmdbMatchIterator mi; Header h; - pkpkt = _free(pkpkt); - pkpktlen = 0; - memset(pksignid, 0, sizeof(pksignid)); + ts->pkpkt = _free(ts->pkpkt); + ts->pkpktlen = 0; + memset(ts->pksignid, 0, sizeof(ts->pksignid)); /* Make sure the database is open. */ (void) rpmtsOpenDB(ts, ts->dbmode); @@ -959,7 +958,7 @@ rpmtsFindPubkey(rpmTransactionSet ts) continue; ix = rpmdbGetIteratorFileNum(mi); if (ix >= pc - || b64decode(pubkeys[ix], (void **) &pkpkt, &pkpktlen)) + || b64decode(pubkeys[ix], (void **) &ts->pkpkt, &ts->pkpktlen)) ix = -1; pubkeys = headerFreeData(pubkeys, pt); break; @@ -967,7 +966,7 @@ rpmtsFindPubkey(rpmTransactionSet ts) mi = rpmdbFreeIterator(mi); /* Was a matching pubkey found? */ - if (ix < 0 || pkpkt == NULL) { + if (ix < 0 || ts->pkpkt == NULL) { res = RPMSIG_NOKEY; goto exit; } @@ -976,15 +975,15 @@ rpmtsFindPubkey(rpmTransactionSet ts) * Can the pubkey packets be parsed? * Do the parameters match the signature? */ - if (pgpPrtPkts(pkpkt, pkpktlen, NULL, 0) + if (pgpPrtPkts(ts->pkpkt, ts->pkpktlen, NULL, 0) && ts->dig->signature.pubkey_algo == ts->dig->pubkey.pubkey_algo #ifdef NOTYET && ts->dig->signature.hash_algo == ts->dig->pubkey.hash_algo #endif && !memcmp(ts->dig->signature.signid, ts->dig->pubkey.signid, 8)) { - pkpkt = _free(pkpkt); - pkpktlen = 0; + ts->pkpkt = _free(ts->pkpkt); + ts->pkpktlen = 0; res = RPMSIG_NOKEY; goto exit; } @@ -992,7 +991,7 @@ rpmtsFindPubkey(rpmTransactionSet ts) /* XXX Verify the pubkey signature. */ /* Packet looks good, save the signer id. */ - memcpy(pksignid, sigp->signid, sizeof(pksignid)); + memcpy(ts->pksignid, sigp->signid, sizeof(ts->pksignid)); rpmMessage(RPMMESS_DEBUG, "========== %s pubkey id %s\n", (sigp->pubkey_algo == PGPPUBKEYALGO_DSA ? "DSA" : @@ -1003,9 +1002,9 @@ rpmtsFindPubkey(rpmTransactionSet ts) #ifdef NOTNOW { - if (pkpkt == NULL) { + if (ts->pkpkt == NULL) { const char * pkfn = rpmExpand("%{_gpg_pubkey}", NULL); - if (pgpReadPkts(pkfn, &pkpkt, &pkpktlen) != PGPARMOR_PUBKEY) { + if (pgpReadPkts(pkfn, &ts->pkpkt, &ts->pkpktlen) != PGPARMOR_PUBKEY) { pkfn = _free(pkfn); res = RPMSIG_NOKEY; goto exit; @@ -1016,7 +1015,7 @@ rpmtsFindPubkey(rpmTransactionSet ts) #endif /* Retrieve parameters from pubkey packet(s). */ - xx = pgpPrtPkts(pkpkt, pkpktlen, ts->dig, 0); + xx = pgpPrtPkts(ts->pkpkt, ts->pkpktlen, ts->dig, 0); /* Do the parameters match the signature? */ if (ts->dig->signature.pubkey_algo == ts->dig->pubkey.pubkey_algo diff --git a/lib/transaction.c b/lib/transaction.c index 69c6f05..0447d69 100644 --- a/lib/transaction.c +++ b/lib/transaction.c @@ -1572,12 +1572,14 @@ fileAction * actions = fi->actions; fi->fstates = NULL; fi->actions = NULL; + psm->fi = fiFree(psm->fi, 1); (void) fiFree(fi, 0); /*@-usereleased@*/ fi->magic = TFIMAGIC; fi->te = p; fi->record = 0; (void) fiNew(ts, fi, h, RPMTAG_BASENAMES, 1); + psm->fi = rpmfiLink(fi, "tsInstall"); fi->fstates = _free(fi->fstates); fi->fstates = fstates; fi->actions = _free(fi->actions); @@ -1611,7 +1613,6 @@ fi->actions = actions; p->fd = NULL; /*@=type@*/ } - (void) fiFree(fi, 0); /*@switchbreak@*/ break; case TR_REMOVED: rpmMessage(RPMMESS_DEBUG, "========== --- %s\n", teGetNEVR(p)); @@ -1620,13 +1621,13 @@ fi->actions = actions; if (psmStage(psm, PSM_PKGERASE)) ourrc++; } - (void) fiFree(fi, 0); /*@switchbreak@*/ break; } xx = rpmdbSync(ts->rpmdb); (void) rpmfiUnlink(psm->fi, "tsInstall"); psm->fi = NULL; psm->te = NULL; + p->fi = fiFree(fi, 1); } /*@=branchstate@*/ pi = teFreeIterator(pi); diff --git a/rpm.spec.in b/rpm.spec.in index a18ee18..0228a05 100644 --- a/rpm.spec.in +++ b/rpm.spec.in @@ -20,7 +20,7 @@ Name: rpm %define version @VERSION@ Version: %{version} %{expand: %%define rpm_version %{version}} -Release: 0.12 +Release: 0.13 Group: System Environment/Base Source: ftp://ftp.rpm.org/pub/rpm/dist/rpm-4.0.x/rpm-%{rpm_version}.tar.gz Copyright: GPL @@ -525,6 +525,7 @@ fi - rework most of rpmdb.c prepatory to implementing duplicates. - fix: 2 memory leaks in headerSprintf. - fix: db mire's access out-of-bounds memory. +- plug most install mode leaks. * Fri May 3 2002 Jeff Johnson 4.1-0.12 - use DBT_DB_MALLOC to eliminate re-malloc'ing header blobs. diff --git a/rpmdb/header.c b/rpmdb/header.c index a046c97..15712cb 100644 --- a/rpmdb/header.c +++ b/rpmdb/header.c @@ -104,8 +104,8 @@ Header XheaderLink(Header h, /*@null@*/ const char * msg, { if (h != NULL) h->nrefs++; /*@-modfilesystem@*/ -if (_h_debug > 0 && msg != NULL) -fprintf(stderr, "--> h %p ++ %d %s at %s:%u\n", h, (h != NULL ? h->nrefs : 0), msg, fn, ln); +if ((_h_debug > 0 || (h->flags & HEADERFLAG_DEBUG)) && msg != NULL) +fprintf(stderr, "--> h %p ++ %d blob %p flags %x %s at %s:%u\n", h, (h != NULL ? h->nrefs : 0), (h != NULL ? h->blob : NULL), (h != NULL ? h->flags : 0), msg, fn, ln); /*@=modfilesystem@*/ /*@-refcounttrans -nullret @*/ return h; @@ -123,8 +123,8 @@ Header XheaderUnlink(/*@killref@*/ /*@null@*/ Header h, /*@modifies h @*/ { /*@-modfilesystem@*/ -if (_h_debug > 0 && msg != NULL) -fprintf(stderr, "--> h %p -- %d %s at %s:%u\n", h, (h != NULL ? h->nrefs : 0), msg, fn, ln); +if ((_h_debug > 0 || (h->flags & HEADERFLAG_DEBUG)) && msg != NULL) +fprintf(stderr, "--> h %p -- %d blob %p flags %x %s at %s:%u\n", h, (h != NULL ? h->nrefs : 0), (h != NULL ? h->blob : NULL), (h != NULL ? h->flags : 0), msg, fn, ln); /*@=modfilesystem@*/ if (h != NULL) h->nrefs--; return NULL; diff --git a/rpmdb/header_internal.h b/rpmdb/header_internal.h index 296efe2..b51dec7 100644 --- a/rpmdb/header_internal.h +++ b/rpmdb/header_internal.h @@ -62,6 +62,7 @@ struct headerToken { #define HEADERFLAG_SORTED (1 << 0) /*!< Are header entries sorted? */ #define HEADERFLAG_ALLOCATED (1 << 1) /*!< Is 1st header region allocated? */ #define HEADERFLAG_LEGACY (1 << 2) /*!< Header came from legacy source? */ +#define HEADERFLAG_DEBUG (1 << 3) /*!< Debug this header? */ /*@refs@*/ int nrefs; /*!< Reference count. */ }; diff --git a/rpmio/rpmpgp.c b/rpmio/rpmpgp.c index 97ec3e4..208505a 100644 --- a/rpmio/rpmpgp.c +++ b/rpmio/rpmpgp.c @@ -1065,6 +1065,20 @@ struct pgpDig_s * pgpFreeDig(/*@only@*/ /*@null@*/ struct pgpDig_s * dig) /*@=branchstate@*/ dig->sha1ctx = NULL; + mp32bfree(&dig->p); + mp32bfree(&dig->q); + mp32nfree(&dig->g); + mp32nfree(&dig->y); + mp32nfree(&dig->hm); + mp32nfree(&dig->r); + mp32nfree(&dig->s); + + mp32bfree(&dig->rsa_pk.n); + mp32nfree(&dig->rsa_pk.e); + mp32nfree(&dig->m); + mp32nfree(&dig->c); + mp32nfree(&dig->hm); + dig = _free(dig); } return dig; -- 2.7.4