diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2011-10-24 12:21:01 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2011-10-24 12:34:07 +0300 |
commit | 97a452f732a256e033c16b4b87a8674b91429b45 (patch) | |
tree | 4951425f021c5c9cd7ebc79a35a554c91c9aa19b | |
parent | b88b2178d40147be6c28dd9b97905ee1dc5366d5 (diff) | |
download | librpm-tizen-97a452f732a256e033c16b4b87a8674b91429b45.tar.gz librpm-tizen-97a452f732a256e033c16b4b87a8674b91429b45.tar.bz2 librpm-tizen-97a452f732a256e033c16b4b87a8674b91429b45.zip |
Sanitize pgpsigFormat()
- Eliminate bogus size calculations: we have a buffer of td->count size
that may or may not contain legal OpenPGP signature. Leave it up to
pgpPrtPkts() to validate & figure it out and check its return code instead,
eliminating need to repeat a bunch of tedious calculations here.
- Use non-zero signature version is used as a hint for valid signature,
should be "close enough" for the rest of the code.
-rw-r--r-- | lib/formats.c | 49 |
1 files changed, 13 insertions, 36 deletions
diff --git a/lib/formats.c b/lib/formats.c index b24d80b3f..fb203559f 100644 --- a/lib/formats.c +++ b/lib/formats.c @@ -422,46 +422,23 @@ static char * pgpsigFormat(rpmtd td) if (rpmtdType(td) != RPM_BIN_TYPE) { val = xstrdup(_("(not a blob)")); } else { - const uint8_t * pkt = td->data; - size_t pktlen = 0; - unsigned int v = *pkt; - pgpTag tag = 0; - size_t plen; - size_t hlen = 0; - - if (v & 0x80) { - if (v & 0x40) { - tag = (v & 0x3f); - plen = pgpLen(pkt+1, &hlen); - } else { - tag = (v >> 2) & 0xf; - plen = (1 << (v & 0x3)); - hlen = pgpGrab(pkt+1, plen); - } - - pktlen = 1 + plen + hlen; - } + pgpDig dig = pgpNewDig(); + pgpDigParams sigp = &dig->signature; - if (pktlen == 0 || tag != PGPTAG_SIGNATURE) { + if (pgpPrtPkts(td->data, td->count, dig, 0) || sigp->version == 0) { val = xstrdup(_("(not an OpenPGP signature)")); } else { - pgpDig dig = pgpNewDig(); - pgpDigParams sigp = &dig->signature; char dbuf[BUFSIZ]; - char *keyid = NULL; - - (void) pgpPrtPkts(pkt, pktlen, dig, 0); - - { unsigned int dateint = pgpGrab(sigp->time, sizeof(sigp->time)); - time_t date = dateint; - struct tm * tms = localtime(&date); - if (!(tms && strftime(dbuf, sizeof(dbuf), "%c", tms) > 0)) { - snprintf(dbuf, sizeof(dbuf), - _("Invalid date %u\n"), dateint); - dbuf[sizeof(dbuf)-1] = '\0'; - } + char *keyid = pgpHexStr(sigp->signid, sizeof(sigp->signid)); + unsigned int dateint = pgpGrab(sigp->time, sizeof(sigp->time)); + time_t date = dateint; + struct tm * tms = localtime(&date); + + if (!(tms && strftime(dbuf, sizeof(dbuf), "%c", tms) > 0)) { + snprintf(dbuf, sizeof(dbuf), + _("Invalid date %u\n"), dateint); + dbuf[sizeof(dbuf)-1] = '\0'; } - keyid = pgpHexStr(sigp->signid, sizeof(sigp->signid)); rasprintf(&val, "%s/%s, %s, Key ID %s\n", pgpValString(PGPVAL_PUBKEYALGO, sigp->pubkey_algo), @@ -469,8 +446,8 @@ static char * pgpsigFormat(rpmtd td) dbuf, keyid); free(keyid); - pgpFreeDig(dig); } + pgpFreeDig(dig); } return val; |