[Rpm-ecosystem] [PATCH v6 04/11] Subroutine for dumping immutable region of header

Lubos Kardos lkardos at redhat.com
Thu Jul 16 14:22:54 UTC 2015


Why utd is an argument of the function unloadImmutableRegion(). No data are
passed with this argument. It contains just empty space that is used inside
the function. It can be replaced with a local variable.


----- Original Message -----
> From: "Mimi Zohar" <zohar at linux.vnet.ibm.com>
> To: rpm-ecosystem at lists.rpm.org
> Cc: fin at linux.vnet.ibm.com, "Fionnuala Gunter" <fionnuala.gunter at gmail.com>
> Sent: Monday, July 6, 2015 8:52:18 PM
> Subject: [Rpm-ecosystem] [PATCH v6 04/11] Subroutine for dumping immutable	region of header
> 
> From: "fin at linux.vnet.ibm.com" <fin at linux.vnet.ibm.com>
> 
> This patch creates a subroutine for dumping the immutable region of
> a header.  It copies the header sections into a new header that can
> be altered.
> ---
>  sign/rpmgensig.c | 47 ++++++++++++++++++++++++++++-------------------
>  1 file changed, 28 insertions(+), 19 deletions(-)
> 
> diff --git a/sign/rpmgensig.c b/sign/rpmgensig.c
> index cf79a87..b660c60 100644
> --- a/sign/rpmgensig.c
> +++ b/sign/rpmgensig.c
> @@ -476,6 +476,33 @@ static int replaceSignature(Header sigh, sigTarget
> sigt1, sigTarget sigt2)
>      return rc;
>  }
>  
> +static void unloadImmutableRegion(Header *hdrp, rpmTagVal tag, rpmtd utd)
> +{
> +    struct rpmtd_s copytd;
> +    Header nh;
> +    Header oh;
> +    HeaderIterator hi;
> +
> +    if (headerGet(*hdrp, tag, utd, HEADERGET_DEFAULT)) {
> +	nh = headerNew();
> +	oh = headerCopyLoad(utd->data);
> +	hi = headerInitIterator(oh);
> +
> +	while (headerNext(hi, &copytd)) {
> +	    if (copytd.data)
> +		headerPut(nh, &copytd, HEADERPUT_DEFAULT);
> +	    rpmtdFreeData(&copytd);
> +	}
> +
> +	headerFreeIterator(hi);
> +	headerFree(oh);
> +	rpmtdFreeData(utd);
> +
> +	*hdrp = headerLink(nh);
*hdrp is overridden and old value is not deallocated

> +	headerFree(nh);
> +    }
> +}
> +
>  /** \ingroup rpmcli
>   * Create/modify elements in signature header.
>   * @param rpm		path to package
> @@ -533,25 +560,7 @@ static int rpmSign(const char *rpm, int deleting)
>  	goto exit;
>      }
>  
> -    /* Dump the immutable region (if present). */
> -    if (headerGet(sigh, RPMTAG_HEADERSIGNATURES, &utd, HEADERGET_DEFAULT)) {
> -	struct rpmtd_s copytd;
> -	Header nh = headerNew();
> -	Header oh = headerCopyLoad(utd.data);
> -	HeaderIterator hi = headerInitIterator(oh);
> -	while (headerNext(hi, &copytd)) {
> -	    if (copytd.data)
> -		headerPut(nh, &copytd, HEADERPUT_DEFAULT);
> -	    rpmtdFreeData(&copytd);
> -	}
> -	headerFreeIterator(hi);
> -	headerFree(oh);
> -	rpmtdFreeData(&utd);
> -
> -	headerFree(sigh);
> -	sigh = headerLink(nh);
> -	headerFree(nh);
> -    }
> +    unloadImmutableRegion(&sigh, RPMTAG_HEADERSIGNATURES, &utd);
>      origSigSize = headerSizeof(sigh, HEADER_MAGIC_YES);
>  
>      if (deleting) {	/* Nuke all the signature tags. */
> --
> 2.1.0
> 
> _______________________________________________
> Rpm-ecosystem mailing list
> Rpm-ecosystem at lists.rpm.org
> http://lists.rpm.org/mailman/listinfo/rpm-ecosystem
>

Lubos  


More information about the Rpm-ecosystem mailing list