Validate all the data types inside BlockerCache._load() so that
authorZac Medico <zmedico@gentoo.org>
Sun, 4 May 2008 00:51:29 +0000 (00:51 -0000)
committerZac Medico <zmedico@gentoo.org>
Sun, 4 May 2008 00:51:29 +0000 (00:51 -0000)
any corruption is detected as soon as possible. (trunk r10147)

svn path=/main/branches/2.1.2/; revision=10148

bin/emerge

index 864ac0be7370c2faa84ca9b19a79359c63730d85..960502e9a8c283cafa32974875774533461617ae 100755 (executable)
@@ -1533,6 +1533,40 @@ class BlockerCache(DictMixin):
                        isinstance(self._cache_data, dict) and \
                        self._cache_data.get("version") == self._cache_version and \
                        isinstance(self._cache_data.get("blockers"), dict)
+               if cache_valid:
+                       # Validate all the atoms and counters so that
+                       # corruption is detected as soon as possible.
+                       for k, v in self._cache_data["blockers"].iteritems():
+                               if not isinstance(k, basestring):
+                                       cache_valid = False
+                                       break
+                               try:
+                                       portage.catpkgsplit(k)
+                               except portage_exception.InvalidData:
+                                       cache_valid = False
+                                       break
+                               if not isinstance(v, tuple) or \
+                                       len(v) != 2:
+                                       cache_valid = False
+                                       break
+                               counter, atoms = v
+                               if not isinstance(counter, (int, long)):
+                                       cache_valid = False
+                                       break
+                               if not isinstance(atoms, list):
+                                       cache_valid = False
+                                       break
+                               for atom in atoms:
+                                       if not isinstance(atom, basestring):
+                                               cache_valid = False
+                                               break
+                                       if atom[:1] != "!" or \
+                                               not portage.isvalidatom(
+                                               atom, allow_blockers=True):
+                                               cache_valid = False
+                                               break
+                               if not cache_valid:
+                                       break
                if not cache_valid:
                        self._cache_data = {"version":self._cache_version}
                        self._cache_data["blockers"] = {}