RPM Community Forums

Mailing List Message of <rpm-cvs>

[CVS] RPM: rpm/ CHANGES rpm/lib/ rpmchecksig.c rpm/rpmdb/ pkgio.c rpmw...

From: Jeff Johnson <jbj@rpm5.org>
Date: Thu 22 Nov 2007 - 18:55:29 CET
Message-Id: <20071122175529.E627534845C@rpm5.org>
  RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  ____________________________________________________________________________

  Server: rpm5.org                         Name:   Jeff Johnson
  Root:   /v/rpm/cvs                       Email:  jbj@rpm5.org
  Module: rpm                              Date:   22-Nov-2007 18:55:29
  Branch: HEAD                             Handle: 2007112217552801

  Modified files:
    rpm                     CHANGES
    rpm/lib                 rpmchecksig.c
    rpm/rpmdb               pkgio.c rpmwf.c
    rpm/rpmio               librpmio.vers rpmio.c rpmxar.c rpmxar.h

  Log:
    - functional (and leak free) -Kvv of both *.rpm and *.xar.
    - revert xar handling to rpmio model, buffer handling in rpmxar.
    - fix: add RPMRC_FAIL where needed using -Kvv.

  Summary:
    Revision    Changes     Path
    1.1866      +3  -0      rpm/CHANGES
    1.192       +9  -1      rpm/lib/rpmchecksig.c
    1.52        +8  -36     rpm/rpmdb/pkgio.c
    1.14        +4  -2      rpm/rpmdb/rpmwf.c
    2.19        +1  -0      rpm/rpmio/librpmio.vers
    1.107       +3  -0      rpm/rpmio/rpmio.c
    2.3         +65 -16     rpm/rpmio/rpmxar.c
    2.3         +18 -4      rpm/rpmio/rpmxar.h
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: rpm/CHANGES
  ============================================================================
  $ cvs diff -u -r1.1865 -r1.1866 CHANGES
  --- rpm/CHANGES	21 Nov 2007 21:58:46 -0000	1.1865
  +++ rpm/CHANGES	22 Nov 2007 17:55:28 -0000	1.1866
  @@ -1,4 +1,7 @@
   5.0a2 -> 5.0a3:
  +    - jbj: functional (and leak free) -Kvv of both *.rpm and *.xar.
  +    - jbj: revert xar handling to rpmio model, buffer handling in rpmxar.
  +    - jbj: fix: add RPMRC_FAIL where needed using -Kvv.
       - jbj: functional (and leak free) queries of both *.rpm and *.xar.
       - jbj: transparently recognize XAR magic when reading.
       - jbj: eliminate rpmpkgClean, rpmxar memory free on Fclose instead.
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/lib/rpmchecksig.c
  ============================================================================
  $ cvs diff -u -r1.191 -r1.192 rpmchecksig.c
  --- rpm/lib/rpmchecksig.c	21 Nov 2007 21:58:47 -0000	1.191
  +++ rpm/lib/rpmchecksig.c	22 Nov 2007 17:55:29 -0000	1.192
  @@ -779,6 +779,7 @@
   	/*@globals fileSystem, internalState @*/
   	/*@modifies fd, fileSystem, internalState @*/
   {
  +rpmxar xar = fdGetXAR(fd);
   pgpDig dig = fdGetDig(fd);
       HGE_t hge = headerGetExtension;
       HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he));
  @@ -813,6 +814,7 @@
   	    if (!xx || he->p.ptr == NULL) {
   		h = headerFree(h);
   		rpmlog(RPMLOG_ERR, _("%s: headerGetEntry failed\n"), fn);
  +		rc = RPMRC_FAIL;
   		goto exit;
   	    }
   	    (void) headerGetMagic(NULL, &hmagic, &nmagic);
  @@ -829,11 +831,17 @@
   	h = headerFree(h);
       }
   
  +if (xar != NULL) {
  +    if ((xx = rpmxarNext(xar)) != 0)	return RPMRC_FAIL;
  +    if ((xx = rpmxarPull(xar, "Payload")) != 0) return RPMRC_FAIL;
  +}
  +
       /* Read the payload from the package. */
       while ((count = Fread(buf, sizeof(buf[0]), sizeof(buf), fd)) > 0)
   	dig->nbytes += count;
  -    if (count < 0) {
  +    if (count < 0 || Ferror(fd)) {
   	rpmlog(RPMLOG_ERR, _("%s: Fread failed: %s\n"), fn, Fstrerror(fd));
  +	rc = RPMRC_FAIL;
   	goto exit;
       }
   
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmdb/pkgio.c
  ============================================================================
  $ cvs diff -u -r1.51 -r1.52 pkgio.c
  --- rpm/rpmdb/pkgio.c	21 Nov 2007 21:58:47 -0000	1.51
  +++ rpm/rpmdb/pkgio.c	22 Nov 2007 17:55:29 -0000	1.52
  @@ -498,10 +498,11 @@
   
       /* With XAR, read lead from a xar archive file called "Lead". */
       if (xar != NULL) {
  -	void *b;
  -	size_t nb;
  +	void *b = NULL;
  +	size_t nb = 0;
   	if ((xx = rpmxarNext(xar)) != 0)	return RPMRC_FAIL;
  -	if ((xx = rpmxarPull(xar, "Lead", &b, &nb)) != 0) return RPMRC_FAIL;
  +	if ((xx = rpmxarPull(xar, "Lead")) != 0) return RPMRC_FAIL;
  +	(void) rpmxarSwapBuf(xar, NULL, 0, &b, &nb);
   	if (nb != sizeof(*l)) {
   	    b = _free(b);
   	    (void) snprintf(buf, sizeof(buf),
  @@ -663,8 +664,6 @@
       rpmRC rc = RPMRC_FAIL;		/* assume failure */
       int xx;
       uint32_t i;
  -    unsigned char * bh = NULL;
  -    size_t nbh = 0;
   
       buf[0] = '\0';
       if (sighp)
  @@ -673,16 +672,13 @@
       memset(block, 0, sizeof(block));
   if (xar != NULL) {
       if ((xx = rpmxarNext(xar)) != 0)	return RPMRC_FAIL;
  -    if ((xx = rpmxarPull(xar, "Signature", &bh, &nbh)) != 0) return RPMRC_FAIL;
  -assert(nbh > sizeof(block));
  -    memcpy(block, bh, sizeof(block));
  -} else {
  +    if ((xx = rpmxarPull(xar, "Signature")) != 0) return RPMRC_FAIL;
  +}
       if ((xx = (int) timedRead(fd, (void *)block, sizeof(block))) != (int) sizeof(block)) {
   	(void) snprintf(buf, sizeof(buf),
   		_("sigh size(%d): BAD, read returned %d\n"), (int)sizeof(block), xx);
   	goto exit;
       }
  -}
   
       {   unsigned char * hmagic = NULL;
   	size_t nmagic = 0;
  @@ -713,17 +709,12 @@
   /*@-sizeoftype@*/
       nb = (il * sizeof(struct entryInfo_s)) + dl;
   /*@=sizeoftype@*/
  -if (xar != NULL) {
  -assert(nbh >= (sizeof(block)+nb));
  -    ei = &((uint32_t *)bh)[2];
  -} else {
       ei = xmalloc(sizeof(il) + sizeof(dl) + nb);
       if ((xx = (int) timedRead(fd, (void *)&ei[2], nb)) != (int) nb) {
   	(void) snprintf(buf, sizeof(buf),
   		_("sigh blob(%u): BAD, read returned %d\n"), (unsigned) nb, xx);
   	goto exit;
       }
  -}
       ei[0] = block[2];
       ei[1] = block[3];
       pe = (entryInfo) &ei[2];
  @@ -811,7 +802,6 @@
   	(void) snprintf(buf, sizeof(buf), _("sigh load: BAD\n"));
   	goto exit;
       }
  -if (xar != NULL) sigh->flags |= HEADERFLAG_XARALLOCATED;
       sigh->flags |= HEADERFLAG_ALLOCATED;
       sigh->flags |= HEADERFLAG_SIGNATURE;
       if (_newmagic)	/* XXX FIXME: sigh needs its own magic. */
  @@ -1228,7 +1218,6 @@
       const char * origin = NULL;
       rpmRC rc = RPMRC_FAIL;		/* assume failure */
       unsigned char * bh = NULL;
  -    size_t nbh = 0;
       int xx;
   
       /* Create (if not already) a signature parameters container. */
  @@ -1245,20 +1234,13 @@
       memset(block, 0, sizeof(block));
   if (xar != NULL) {
       if ((xx = rpmxarNext(xar)) != 0)	return RPMRC_FAIL;
  -    if ((xx = rpmxarPull(xar, "Header", &bh, &nbh)) != 0) return RPMRC_FAIL;
  -    if (nbh <= sizeof(block)) {
  -	(void) snprintf(buf, sizeof(buf),
  -		_("hdr size(%u): BAD, xar read returned %u\n"), (unsigned)sizeof(block), (unsigned)nb);
  -	goto exit;
  -    }
  -    memcpy(block, bh, sizeof(block));
  -} else {
  +    if ((xx = rpmxarPull(xar, "Header")) != 0) return RPMRC_FAIL;
  +}
       if ((xx = (int) timedRead(fd, (char *)block, sizeof(block))) != (int)sizeof(block)) {
   	(void) snprintf(buf, sizeof(buf),
   		_("hdr size(%u): BAD, read returned %d\n"), (unsigned)sizeof(block), xx);
   	goto exit;
       }
  -}
   
       b = NULL;
       nb = 0;
  @@ -1286,14 +1268,6 @@
       nb = (il * sizeof(struct entryInfo_s)) + dl;
   /*@=sizeoftype@*/
       uc = sizeof(il) + sizeof(dl) + nb;
  -if (xar != NULL) {
  -    if (nbh != (sizeof(block)+nb)) {
  -	(void) snprintf(buf, sizeof(buf),
  -		_("hdr size(%u): BAD, xar read returned %u\n"), (unsigned)(sizeof(block)+nb), (unsigned)nb);
  -	goto exit;
  -    }
  -    ei = &((uint32_t *)bh)[2];
  -} else {
       bh = xmalloc(uc);
       ei = (uint32_t *)bh;
       if ((xx = (int) timedRead(fd, (char *)&ei[2], nb)) != (int) nb) {
  @@ -1301,7 +1275,6 @@
   		_("hdr blob(%u): BAD, read returned %d\n"), (unsigned)nb, xx);
   	goto exit;
       }
  -}
       ei[0] = block[2];
       ei[1] = block[3];
   
  @@ -1316,7 +1289,6 @@
   	(void) snprintf(buf, sizeof(buf), _("hdr load: BAD\n"));
           goto exit;
       }
  -if (xar != NULL) h->flags |= HEADERFLAG_XARALLOCATED;
       h->flags |= HEADERFLAG_ALLOCATED;
       bh = NULL;	/* XXX will be freed with header */
   
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmdb/rpmwf.c
  ============================================================================
  $ cvs diff -u -r1.13 -r1.14 rpmwf.c
  --- rpm/rpmdb/rpmwf.c	21 Nov 2007 18:21:47 -0000	1.13
  +++ rpm/rpmdb/rpmwf.c	22 Nov 2007 17:55:29 -0000	1.14
  @@ -38,7 +38,8 @@
   	nb = wf->np;
       }
   
  -    xx = rpmxarPush(wf->xar, fn, b, nb);
  +    xx = rpmxarSwapBuf(wf->xar, b, nb, NULL, NULL);
  +    xx = rpmxarPush(wf->xar, fn);
       return (xx == 0 ? RPMRC_OK : RPMRC_FAIL);
   }
   
  @@ -49,9 +50,10 @@
       size_t nb = 0;
       int xx;
   
  -    xx = rpmxarPull(wf->xar, fn, &b, &nb);
  +    xx = rpmxarPull(wf->xar, fn);
       if (xx == 1)
   	return RPMRC_NOTFOUND;
  +    xx = rpmxarSwapBuf(wf->xar, NULL, 0, &b, &nb);
   
       if (!strcmp(fn, "Lead")) {
   	wf->l = b;
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/librpmio.vers
  ============================================================================
  $ cvs diff -u -r2.18 -r2.19 librpmio.vers
  --- rpm/rpmio/librpmio.vers	21 Nov 2007 18:21:47 -0000	2.18
  +++ rpm/rpmio/librpmio.vers	22 Nov 2007 17:55:29 -0000	2.19
  @@ -305,6 +305,7 @@
       rpmxarNext;
       rpmxarPush;
       rpmxarPull;
  +    rpmxarSwapBuf;
       XrpmxarUnlink;
       Stat;
       _Stat;
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/rpmio.c
  ============================================================================
  $ cvs diff -u -r1.106 -r1.107 rpmio.c
  --- rpm/rpmio/rpmio.c	21 Nov 2007 21:58:48 -0000	1.106
  +++ rpm/rpmio/rpmio.c	22 Nov 2007 17:55:29 -0000	1.107
  @@ -419,6 +419,9 @@
   	if (rc == 0)
   	    fd->bytesRemain = 0;
       } else
  +    if (fd->xar != NULL) {
  +	rc = xarRead(fd, buf, (count > fd->bytesRemain ? fd->bytesRemain : count));
  +    } else
   	rc = read(fdFileno(fd), buf, (count > fd->bytesRemain ? fd->bytesRemain : count));
       fdstat_exit(fd, FDSTAT_READ, rc);
   
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/rpmxar.c
  ============================================================================
  $ cvs diff -u -r2.2 -r2.3 rpmxar.c
  --- rpm/rpmio/rpmxar.c	21 Nov 2007 18:21:47 -0000	2.2
  +++ rpm/rpmio/rpmxar.c	22 Nov 2007 17:55:29 -0000	2.3
  @@ -1,9 +1,9 @@
   #include "system.h"
   #include "xar.h"
   
  -#include <rpmio.h>
  -
   #define	_RPMXAR_INTERNAL
  +#include <rpmio_internal.h>
  +
   #include <rpmxar.h>
   
   #include "debug.h"
  @@ -61,6 +61,9 @@
   	    xar->x = NULL;
   	}
   
  +	xar->member = _free(xar->member);
  +	xar->b = _free(xar->b);
  +
   	(void) rpmxarUnlink(xar, "rpmxarFree");
   /*@=onlytrans@*/
   	/*@-refcounttrans -usereleased@*/
  @@ -102,11 +105,11 @@
       return (xar->f == NULL ? 1 : 0);
   }
   
  -int rpmxarPush(rpmxar xar, const char * fn, void * b, size_t nb)
  +int rpmxarPush(rpmxar xar, const char * fn)
   {
  -    if (xar->x && b != NULL && nb > 0) {
  +    if (xar->x && xar->b != NULL) {
   /*@-moduncon@*/
  -	xar->f = xar_add_frombuffer(xar->x, NULL, fn, b, nb);
  +	xar->f = xar_add_frombuffer(xar->x, NULL, fn, xar->b, xar->bsize);
   /*@=moduncon@*/
   	if (xar->f == NULL)
   	    return 2;
  @@ -114,34 +117,80 @@
       return 0;
   }
   
  -int rpmxarPull(rpmxar xar, const char * fn, void * bp, size_t * nbp)
  +int rpmxarPull(rpmxar xar, const char * fn)
   {
   /*@-moduncon@*/
       const char * path = xar_get_path(xar->f);
   /*@=moduncon@*/
  -    char * b = NULL;
  -    size_t nb = 0;
       int rc;
   
       if (fn != NULL && strcmp(fn, path)) {
   	path = _free(path);
   	return 1;
       }
  +    xar->member = _free(xar->member);
  +    xar->member = path;
  +
  +    xar->b = _free(xar->b);
  +    xar->bsize = xar->bx = 0;
   
   /*@-moduncon@*/
  -    rc = (int) xar_extract_tobuffersz(xar->x, xar->f, &b, &nb);
  +    rc = (int) xar_extract_tobuffersz(xar->x, xar->f, &xar->b, &xar->bsize);
   /*@=moduncon@*/
   if (_xar_debug)
  -fprintf(stderr, "*** %s %p[%lu] rc %d\n", path, b, (unsigned long)nb, rc);
  -    path = _free(path);
  -    if (rc || b == NULL || nb == 0)
  +fprintf(stderr, "*** %s %p[%lu] rc %d\n", xar->member, xar->b, (unsigned long)xar->bsize, rc);
  +    if (rc)
   	return 1;
   
  -    if (bp)
  -	*((char **)bp) = b;
  -    if (nbp)
  -	*nbp = nb;
  +    return 0;
  +}
   
  +int rpmxarSwapBuf(rpmxar xar, char * b, size_t bsize,
  +		char ** obp, size_t * obsizep)
  +{
  +if (_xar_debug)
  +fprintf(stderr, "*** rpmxarSwapBuf(%p, %p[%u], %p, %p) %p[%u]\n", xar, b, (unsigned) bsize, obp, obsizep, xar->b, (unsigned) xar->bsize);
  +    if (xar) {
  +	if (obsizep != NULL)
  +	    *obsizep = xar->bsize;
  +	if (obp != NULL) {
  +	    *obp = xar->b;
  +	    xar->b = NULL;
  +	}
  +	xar->b = _free(xar->b);
  +	xar->b = b;
  +	xar->bsize = bsize;
  +    }
       return 0;
   }
  +
  +ssize_t xarRead(void * cookie, /*@out@*/ char * buf, size_t count)
  +{
  +    FD_t fd = cookie;
  +    rpmxar xar = fdGetXAR(fd);
  +    ssize_t rc = 0;
  +
  +assert(xar != NULL);
  +#if 0
  +    if ((xx = rpmxarNext(xar)) != 0)    return RPMRC_FAIL;
  +    if ((xx = rpmxarPull(xar, "Signature")) != 0) return RPMRC_FAIL;
  +    (void) rpmxarSwapBuf(xar, NULL, 0, &b, &nb);
  +#endif
  +
  +    rc = xar->bsize - xar->bx;
  +    if (rc > 0) {
  +	if (count < rc) rc = count;
  +	memmove(buf, &xar->b[xar->bx], rc);
  +	xar->bx += rc;
  +    } else
  +    if (rc < 0) {
  +	rc = -1;
  +    } else
  +	rc = 0;
  +
  +if (_xar_debug)
  +fprintf(stderr, "*** xarRead(%p,%p,0x%x) %s %p[%u:%u] rc 0x%x\n", cookie, buf, (unsigned)count, xar->member, xar->b, (unsigned)xar->bx, (unsigned)xar->bsize, (unsigned)rc);
  +
  +    return rc;
  +}
   #endif
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/rpmxar.h
  ============================================================================
  $ cvs diff -u -r2.2 -r2.3 rpmxar.h
  --- rpm/rpmio/rpmxar.h	21 Nov 2007 18:21:47 -0000	2.2
  +++ rpm/rpmio/rpmxar.h	22 Nov 2007 17:55:29 -0000	2.3
  @@ -8,10 +8,15 @@
   
   #ifdef	_RPMXAR_INTERNAL
   struct rpmxar_s {
  -    int first;
       xar_t x;
       xar_file_t f;
       xar_iter_t i;
  +/*@null@*/
  +    const char * member;	/*!< Current archive member. */
  +    char * b;			/*!< Data buffer. */
  +    size_t bsize;		/*!< No. bytes of data. */
  +    size_t bx;			/*!< Data byte index. */
  +    int first;
   /*@refs@*/
       int nrefs;			/*!< Reference count. */
   };
  @@ -71,14 +76,23 @@
   	/*@globals fileSystem @*/
   	/*@modifies xar, fileSystem @*/;
   
  -int rpmxarPush(rpmxar xar, const char * fn, void * b, size_t nb)
  +int rpmxarPush(rpmxar xar, const char * fn)
   	/*@modifies xar @*/;
   
  -int rpmxarPull(rpmxar xar, /*@null@*/ const char * fn,
  -		/*@null@*/ void * bp, /*@null@*/ size_t * nbp)
  +int rpmxarPull(rpmxar xar, /*@null@*/ const char * fn)
   	/*@globals fileSystem @*/
   	/*@modifies xar, fileSystem @*/;
   
  +int rpmxarSwapBuf(rpmxar xar, /*@null@*/ char * b, size_t bsize,
  +		/*@null@*/ char ** obp, /*@null@*/ size_t * obsizep)
  +	/*@modifies xar, *obp, *obsizep @*/;
  +
  +ssize_t xarRead(void * cookie, /*@out@*/ char * buf, size_t count)
  +        /*@globals fileSystem, internalState @*/
  +        /*@modifies buf, fileSystem, internalState @*/
  +	/*@requires maxSet(buf) >= (count - 1) @*/
  +	/*@ensures maxRead(buf) == result @*/;
  +
   #ifdef __cplusplus
   }
   #endif
  @@ .
Received on Thu Nov 22 18:55:29 2007
Driven by Jeff Johnson and the RPM project team.
Hosted by OpenPKG and Ralf S. Engelschall.
Powered by FreeBSD and OpenPKG.