Add basic sanity check for global update entries
authorMarius Mauch <genone@gentoo.org>
Thu, 16 Feb 2006 13:10:56 +0000 (13:10 -0000)
committerMarius Mauch <genone@gentoo.org>
Thu, 16 Feb 2006 13:10:56 +0000 (13:10 -0000)
svn path=/main/trunk/; revision=2718

pym/portage.py
pym/portage_exception.py

index 880864c4e2b0c6eeb0e4f896d2e27d960e703ee3..c41878ff7f6f783d361b08edadcf624977479f98 100644 (file)
@@ -4316,6 +4316,10 @@ class vardbapi(dbapi):
        def move_ent(self,mylist):
                origcp=mylist[1]
                newcp=mylist[2]
+               # sanity check
+               for cp in [origcp,newcp]:
+                       if not (isvalidatom(cp) and isjustname(cp)):
+                               raise portage_exception.InvalidPackageName(cp)
                origmatches=self.match(origcp,use_cache=0)
                if not origmatches:
                        return
@@ -4364,7 +4368,11 @@ class vardbapi(dbapi):
                origslot=mylist[2]
                newslot=mylist[3]
 
+               if not isvalidatom(pkg):
+                       raise portage_exception.InvalidAtom(pkg)
+
                origmatches=self.match(pkg,use_cache=0)
+               
                if not origmatches:
                        return
                for mycpv in origmatches:
@@ -5251,6 +5259,10 @@ class binarytree(packagetree):
                        self.populate()
                origcp=mylist[1]
                newcp=mylist[2]
+               # sanity check
+               for cp in [origcp,newcp]:
+                       if not (isvalidatom(cp) and isjustname(cp)):
+                               raise portage_exception.InvalidPackageName(cp)
                mynewcat=newcp.split("/")[0]
                origmatches=self.dbapi.cp_list(origcp)
                if not origmatches:
@@ -5307,6 +5319,10 @@ class binarytree(packagetree):
                pkg=mylist[1]
                origslot=mylist[2]
                newslot=mylist[3]
+               
+               if not isvalidatom(pkg):
+                       raise portage_exception.InvalidAtom(pkg)
+               
                origmatches=self.dbapi.match(pkg)
                if not origmatches:
                        return
@@ -6804,8 +6820,12 @@ def do_upgrade(mykey):
                sys.stdout.flush()
 
                if mysplit[0]=="move":
-                       db["/"]["vartree"].dbapi.move_ent(mysplit)
-                       db["/"]["bintree"].move_ent(mysplit)
+                       try:
+                               db["/"]["vartree"].dbapi.move_ent(mysplit)
+                               db["/"]["bintree"].move_ent(mysplit)
+                       except portage_exception.InvalidPackageName, e:
+                               writemsg("\nERROR: Malformed update entry '%s'\n" % myline)
+                               continue
                        #update world entries:
                        for x in range(0,len(worldlist)):
                                #update world entries, if any.
@@ -6825,8 +6845,11 @@ def do_upgrade(mykey):
                                                sys.stdout.flush()
 
                elif mysplit[0]=="slotmove":
-                       db["/"]["vartree"].dbapi.move_slot_ent(mysplit)
-                       db["/"]["bintree"].move_slot_ent(mysplit,settings["PORTAGE_TMPDIR"]+"/tbz2")
+                       try:
+                               db["/"]["vartree"].dbapi.move_slot_ent(mysplit)
+                               db["/"]["bintree"].move_slot_ent(mysplit,settings["PORTAGE_TMPDIR"]+"/tbz2")
+                       except portage_exception.InvalidAtom, e:
+                               writemsg("\nERROR: Malformed update entry '%s'\n" % myline)
 
        for x in update_files:
                mydblink = dblink('','','/',settings)
index d810876f1eeb03f42117327b4072f87aac9037bb..ae3a9db4f374d37cd9e72a2d4a38ab3e36cd7b8d 100644 (file)
@@ -58,6 +58,9 @@ class PackageNotFound(PortagePackageException):
 class InvalidPackageName(PortagePackageException):
        """Malformed package name"""
 
+class InvalidAtom(PortagePackageException):
+       """Malformed atom spec"""
+
 class UnsupportedAPIException(PortagePackageException):
        """Unsupported API"""
        def __init__(self, cpv, api):