From: Panu Matilainen Date: Fri, 4 Nov 2011 10:32:17 +0000 (+0200) Subject: Arrange temporary storage for parsing if called with NULL dig X-Git-Tag: rpm-4.10.0-beta1~255 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=568811cb6bf4bf9b4395ebc2d5a6459bec839c74;p=platform%2Fupstream%2Frpm.git Arrange temporary storage for parsing if called with NULL dig - The only known caller with NULL dig is in the rather useless wrapping of prtPrtPkts() in the python bindings, but since in theory some other callers could use this just for validating a PGP packet .. preserve the behavior since it's easy. The actual benefit here is that this frees the parser internals of having to check for NULL pointers everywhere. --- diff --git a/rpmio/rpmpgp.c b/rpmio/rpmpgp.c index 2be3154..f197441 100644 --- a/rpmio/rpmpgp.c +++ b/rpmio/rpmpgp.c @@ -1139,18 +1139,22 @@ int pgpPrtPkts(const uint8_t * pkts, size_t pktlen, pgpDig dig, int printing) const uint8_t *p; size_t pleft; int len; + struct pgpDigParams_s tmp; pgpDigParams _digp = NULL; + unsigned int tag; if (!(val & 0x80)) return -1; _print = printing; + tag = (val & 0x40) ? (val & 0x3f) : ((val >> 2) & 0xf); if (dig != NULL) { - pgpTag tag = (val & 0x40) ? (val & 0x3f) : ((val >> 2) & 0xf); _digp = (tag == PGPTAG_SIGNATURE) ? &dig->signature : &dig->pubkey; - _digp->tag = tag; - } else - _digp = NULL; + } else { + _digp = &tmp; + memset(_digp, 0, sizeof(*_digp)); + } + _digp->tag = tag; for (p = pkts, pleft = pktlen; p < (pkts + pktlen); p += len, pleft -= len) { len = pgpPrtPkt(p, pleft, _digp); @@ -1159,6 +1163,10 @@ int pgpPrtPkts(const uint8_t * pkts, size_t pktlen, pgpDig dig, int printing) if (len > pleft) /* XXX shouldn't happen */ break; } + + if (_digp == &tmp) + pgpCleanDigParams(_digp); + return 0; }