Added sanity checks on pgpPrtPkts() entry
authorPanu Matilainen <pmatilai@redhat.com>
Fri, 4 Nov 2011 10:24:32 +0000 (12:24 +0200)
committerPanu Matilainen <pmatilai@redhat.com>
Fri, 4 Nov 2011 10:24:32 +0000 (12:24 +0200)
- Error out cleanly on NULL pkts pointer (caller error but not worth
  dying for)
- Error out early if packet is clearly not valid

rpmio/rpmpgp.c

index 1765110..2be3154 100644 (file)
@@ -1135,14 +1135,17 @@ pgpDig pgpFreeDig(pgpDig dig)
 
 int pgpPrtPkts(const uint8_t * pkts, size_t pktlen, pgpDig dig, int printing)
 {
-    unsigned int val = *pkts;
+    unsigned int val = (pkts != NULL) ? *pkts : 0;
     const uint8_t *p;
     size_t pleft;
     int len;
     pgpDigParams _digp = NULL;
 
+    if (!(val & 0x80))
+       return -1;
+
     _print = printing;
-    if (dig != NULL && (val & 0x80)) {
+    if (dig != NULL) {
        pgpTag tag = (val & 0x40) ? (val & 0x3f) : ((val >> 2) & 0xf);
        _digp = (tag == PGPTAG_SIGNATURE) ? &dig->signature : &dig->pubkey;
        _digp->tag = tag;