Sanity check region length on header load
authorPanu Matilainen <pmatilai@redhat.com>
Mon, 3 Oct 2011 14:49:29 +0000 (17:49 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Mon, 3 Oct 2011 14:59:18 +0000 (17:59 +0300)
- Region size can't obviously be larger than the containing header,
  sanity check to avoid crashes from malformed packages.
- We should really test for length equality here, but with dribbles
  the size is sometimes off by three, whatever the reason (bug likely),
  leaving that investigation for some sunnier day...

lib/header.c

index c771967..b01d1e4 100644 (file)
@@ -895,6 +895,11 @@ Header headerLoad(void * uh)
            h->indexUsed += ne;
          }
        }
+
+       rdlen += REGION_TAG_COUNT;
+       /* XXX should be equality test, but dribbles are sometimes a bit off? */
+       if (rdlen > dl || (rdlen < dl && ril == h->indexUsed))
+           goto errxit;
     }
 
     h->flags &= ~HEADERFLAG_SORTED;