RPM Package Manager, CVS Repository http://rpm5.org/cvs/ ____________________________________________________________________________
Server: rpm5.org Name: Jeff Johnson Root: /v/rpm/cvs Email: j...@rpm5.org Module: rpm Date: 24-May-2009 20:36:10 Branch: HEAD Handle: 2009052418361000 Modified files: rpm CHANGES rpm/rpmio digest.c iosm.c poptIO.c rpmio.c Log: - jbj: yarn: convert DIGEST_CTX to usage mutex with refcounts. Summary: Revision Changes Path 1.2992 +1 -0 rpm/CHANGES 2.49 +52 -18 rpm/rpmio/digest.c 1.40 +1 -1 rpm/rpmio/iosm.c 1.50 +4 -0 rpm/rpmio/poptIO.c 1.194 +3 -0 rpm/rpmio/rpmio.c ____________________________________________________________________________ patch -p0 <<'@@ .' Index: rpm/CHANGES ============================================================================ $ cvs diff -u -r1.2991 -r1.2992 CHANGES --- rpm/CHANGES 23 May 2009 15:48:43 -0000 1.2991 +++ rpm/CHANGES 24 May 2009 18:36:10 -0000 1.2992 @@ -1,5 +1,6 @@ 5.2b1 -> 5.3a1 + - jbj: yarn: convert DIGEST_CTX to usage mutex with refcounts. - jbj: eliminate (unused) DB_DBT_MALLOC flag while loading rpmdb headers. - jbj: bump sonames to libfoo-5.2. - jbj: rpmmi: rename the other methods for the match iterator object. @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/digest.c ============================================================================ $ cvs diff -u -r2.48 -r2.49 digest.c --- rpm/rpmio/digest.c 2 Mar 2009 00:45:55 -0000 2.48 +++ rpm/rpmio/digest.c 24 May 2009 18:36:10 -0000 2.49 @@ -22,8 +22,11 @@ #include "debug.h" -#ifdef SHA_DEBUG -#define DPRINTF(_a) fprintf _a +/*...@unchecked@*/ +int _ctx_debug = 0; + +#ifdef _DIGEST_DEBUG +#define DPRINTF(_a) if (_ctx_debug < 0) fprintf _a #else #define DPRINTF(_a) #endif @@ -35,9 +38,10 @@ /*...@access digest_...@*/ /** - * MD5/SHA1 digest private data. + * Digest private data. */ struct DIGEST_CTX_s { + struct rpmioItem_s _item; /*!< usage mutex and pool identifier. */ /*...@observer@*/ const char * name; /*!< Digest name. */ size_t paramsize; /*!< No. bytes of digest parameters. */ @@ -46,7 +50,7 @@ int (*Reset) (void * param) /*...@modifies param @*/; /*!< Digest initialize. */ int (*Update) (void * param, const byte * data, size_t size) - /*...@modifies param @*/; /*!< Digest transform. */ + /*...@modifies param @*/; /*!< Digest update. */ int (*Digest) (void * param, /*...@out@*/ byte * digest) /*...@modifies param, digest @*/; /*!< Digest finish. */ pgpHashAlgo hashalgo; /*!< RFC 2440/4880 hash algorithm id. */ @@ -56,6 +60,30 @@ void * param; /*!< Digest parameters. */ }; +static void ctxFini(void * _ctx) + /*...@modifies _ctx @*/ +{ + DIGEST_CTX ctx = _ctx; + if (ctx->param != NULL && ctx->paramsize > 0) + memset(ctx->param, 0, ctx->paramsize); /* In case it's sensitive */ + ctx->param = _free(ctx->param); +} + +/*...@unchecked@*/ /*...@only@*/ /*...@null@*/ +rpmioPool _ctxPool; + +static DIGEST_CTX ctxGetPool(rpmioPool pool) +{ + DIGEST_CTX ctx; + + if (_ctxPool == NULL) { + _ctxPool = rpmioNewPool("ctx", sizeof(*ctx), -1, _ctx_debug, + NULL, NULL, ctxFini); + pool = _ctxPool; + } + return (DIGEST_CTX) rpmioGetPool(pool, sizeof(*ctx)); +} + pgpHashAlgo rpmDigestAlgo(DIGEST_CTX ctx) { return (ctx != NULL ? ctx->hashalgo : PGPHASHALGO_NONE); @@ -71,20 +99,29 @@ return (ctx != NULL ? ctx->asn1 : NULL); } - DIGEST_CTX rpmDigestDup(DIGEST_CTX octx) { - DIGEST_CTX nctx; - nctx = memcpy(xcalloc(1, sizeof(*nctx)), octx, sizeof(*nctx)); + DIGEST_CTX nctx = ctxGetPool(_ctxPool); + + nctx->name = octx->name; + nctx->digestsize = octx->digestsize; + nctx->datasize = octx->datasize; + nctx->paramsize = octx->paramsize; + nctx->Reset = octx->Reset; + nctx->Update = octx->Update; + nctx->Digest = octx->Digest; + nctx->hashalgo = octx->hashalgo; + nctx->flags = octx->flags; + nctx->asn1 = octx->asn1; nctx->param = memcpy(xcalloc(1, nctx->paramsize), octx->param, nctx->paramsize); - return nctx; + return (DIGEST_CTX)rpmioLinkPoolItem((rpmioItem)nctx, __FUNCTION__, __FILE__, __LINE__); } DIGEST_CTX rpmDigestInit(pgpHashAlgo hashalgo, rpmDigestFlags flags) { - DIGEST_CTX ctx = xcalloc(1, sizeof(*ctx)); + DIGEST_CTX ctx = ctxGetPool(_ctxPool); int xx; ctx->hashalgo = hashalgo; @@ -385,15 +422,15 @@ #endif case PGPHASHALGO_HAVAL_5_160: default: - free(ctx); + (void)rpmioFreePoolItem((rpmioItem)ctx, __FUNCTION__, __FILE__, __LINE__); return NULL; /*...@notreached@*/ break; } xx = (*ctx->Reset) (ctx->param); -DPRINTF((stderr, "*** Init(%x) ctx %p param %p\n", flags, ctx, ctx->param)); - return ctx; +DPRINTF((stderr, "==> ctx %p ==== Init(%s, %x) param %p\n", ctx, ctx->name, flags, ctx->param)); + return (DIGEST_CTX)rpmioLinkPoolItem((rpmioItem)ctx, __FUNCTION__, __FILE__, __LINE__); } /*...@-mustmod@*/ /* LCL: ctx->param may be modified, but ctx is abstract @*/ @@ -403,7 +440,7 @@ if (ctx == NULL) return -1; -DPRINTF((stderr, "*** Update(%p,%p,%d) param %p \"%s\"\n", ctx, data, len, ctx->param, ((char *)data))); +DPRINTF((stderr, "==> ctx %p ==== Update(%s,%p[%u]) param %p\n", ctx, ctx->name, data, (unsigned)len, ctx->param)); return (*ctx->Update) (ctx->param, data, len); } /*...@=mustmod@*/ @@ -418,7 +455,7 @@ return -1; digest = xmalloc(ctx->digestsize); -DPRINTF((stderr, "*** Final(%p,%p,%p,%d) param %p digest %p\n", ctx, datap, lenp, asAscii, ctx->param, digest)); +DPRINTF((stderr, "==> ctx %p ==== Final(%s,%p,%p,%d) param %p digest %p\n", ctx, ctx->name, datap, lenp, asAscii, ctx->param, digest)); /*...@-noeffectuncon@*/ /* FIX: check rc */ (void) (*ctx->Digest) (ctx->param, digest); /*...@=noeffectuncon@*/ @@ -449,9 +486,6 @@ memset(digest, 0, ctx->digestsize); /* In case it's sensitive */ free(digest); } - memset(ctx->param, 0, ctx->paramsize); /* In case it's sensitive */ - free(ctx->param); - memset(ctx, 0, sizeof(*ctx)); /* In case it's sensitive */ - free(ctx); + (void)rpmioFreePoolItem((rpmioItem)ctx, __FUNCTION__, __FILE__, __LINE__); return 0; } @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/iosm.c ============================================================================ $ cvs diff -u -r1.39 -r1.40 iosm.c --- rpm/rpmio/iosm.c 14 May 2009 16:58:26 -0000 1.39 +++ rpm/rpmio/iosm.c 24 May 2009 18:36:10 -0000 1.40 @@ -1,5 +1,5 @@ /** \ingroup payload - * \file rpmmi/iosm.c + * \file rpmio/iosm.c * File state machine to handle a payload from a package. */ @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/poptIO.c ============================================================================ $ cvs diff -u -r1.49 -r1.50 poptIO.c --- rpm/rpmio/poptIO.c 18 Apr 2009 16:41:58 -0000 1.49 +++ rpm/rpmio/poptIO.c 24 May 2009 18:36:10 -0000 1.50 @@ -55,6 +55,8 @@ /*...@unchecked@*/ extern int _cpio_debug; /*...@unchecked@*/ +extern int _ctx_debug; +/*...@unchecked@*/ extern int _dav_debug; /*...@unchecked@*/ extern int _ftp_debug; @@ -396,6 +398,8 @@ N_("Debug argv collections"), NULL}, { "cpiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_cpio_debug, -1, N_("Debug cpio archives"), NULL}, + { "ctxdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_ctx_debug, -1, + N_("Debug digest contexts"), NULL}, { "davdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_dav_debug, -1, N_("Debug WebDAV data stream"), NULL}, { "ftpdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_ftp_debug, -1, @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/rpmio.c ============================================================================ $ cvs diff -u -r1.193 -r1.194 rpmio.c --- rpm/rpmio/rpmio.c 12 May 2009 13:44:07 -0000 1.193 +++ rpm/rpmio/rpmio.c 24 May 2009 18:36:10 -0000 1.194 @@ -3132,6 +3132,7 @@ /*...@-shadow@*/ extern rpmioPool _mirePool; extern rpmioPool _htPool; + extern rpmioPool _ctxPool; extern rpmioPool _rpmsyckPool; /*...@=shadow@*/ extern rpmioPool _rpmmgPool; @@ -3173,9 +3174,11 @@ _rpmficlPool = rpmioFreePool(_rpmficlPool); _rpmluavPool = rpmioFreePool(_rpmluavPool); _rpmluaPool = rpmioFreePool(_rpmluaPool); + _mirePool = rpmioFreePool(_mirePool); _rpmmgPool = rpmioFreePool(_rpmmgPool); _htPool = rpmioFreePool(_htPool); + _ctxPool = rpmioFreePool(_ctxPool); _rpmsyckPool = rpmioFreePool(_rpmsyckPool); _rpmiobPool = rpmioFreePool(_rpmiobPool); _digPool = rpmioFreePool(_digPool); @@ . ______________________________________________________________________ RPM Package Manager http://rpm5.org CVS Sources Repository rpm-cvs@rpm5.org