For bug #181355, detect parenthesis mismatch in paren_reduce(), raise an InvalidDepen...
authorZac Medico <zmedico@gentoo.org>
Mon, 11 Jun 2007 02:05:43 +0000 (02:05 -0000)
committerZac Medico <zmedico@gentoo.org>
Mon, 11 Jun 2007 02:05:43 +0000 (02:05 -0000)
svn path=/main/trunk/; revision=6796

bin/repoman
pym/portage/__init__.py
pym/portage/dbapi/bintree.py
pym/portage/dep.py

index 5f7160024d89b4c24c8ce5d7150f9ad7b2fb05a0..5b16ae0b14c2357a38de650324736042c940bd68 100755 (executable)
@@ -1141,6 +1141,10 @@ for x in scanlist:
                        except ValueError:
                                badsyntax.append("parenthesis mismatch")
                                mydeplist = []
+                       except portage.exception.InvalidDependString, e:
+                               badsyntax.append(str(e))
+                               del e
+                               mydeplist = []
 
                        try:
                                portage.dep.use_reduce(mydeplist, excludeall=myiuse)
index 0b544438790ee35084b1078c54b682e3248fbe1d..ed440bcbebaa7f50b866c875071e4f11c8fe07e6 100644 (file)
@@ -3228,9 +3228,14 @@ def doebuild_environment(myebuild, mydo, myroot, mysettings, debug, use_cache, m
                if not eapi_is_supported(eapi):
                        # can't do anything with this.
                        raise portage.exception.UnsupportedAPIException(mycpv, eapi)
-               mysettings["PORTAGE_RESTRICT"] = " ".join(flatten(
-                       portage.dep.use_reduce(portage.dep.paren_reduce(
-                       mysettings["RESTRICT"]), uselist=mysettings["USE"].split())))
+               try:
+                       mysettings["PORTAGE_RESTRICT"] = " ".join(flatten(
+                               portage.dep.use_reduce(portage.dep.paren_reduce(
+                               mysettings.get("RESTRICT","")),
+                               uselist=mysettings.get("USE","").split())))
+               except portage.exception.InvalidDependString:
+                       # RESTRICT is validated again inside doebuild, so let this go
+                       mysettings["PORTAGE_RESTRICT"] = ""
 
        if mysplit[2] == "r0":
                mysettings["PVR"]=mysplit[1]
@@ -4515,7 +4520,10 @@ def dep_check(depstring, mydbapi, mysettings, use="yes", mode=None, myuse=None,
                myusesplit=[]
 
        #convert parenthesis to sublists
-       mysplit = portage.dep.paren_reduce(depstring)
+       try:
+               mysplit = portage.dep.paren_reduce(depstring)
+       except portage.exception.InvalidDependString, e:
+               return [0, str(e)]
 
        mymasks = set()
        useforce = set()
index 31086a5c54e1aa9535e97c13e89b10389f3a4d6c..7fb58748f0b40c0486e84fdf5524fb93b4e4b22e 100644 (file)
@@ -718,10 +718,19 @@ class binarytree(object):
                        from portage.dep import paren_reduce, use_reduce, \
                                paren_normalize, paren_enclose
                        for k in "LICENSE", "RDEPEND", "DEPEND", "PDEPEND", "PROVIDE":
-                               deps = paren_reduce(d[k])
-                               deps = use_reduce(deps, uselist=use)
-                               deps = paren_normalize(deps)
-                               deps = paren_enclose(deps)
+                               try:
+                                       deps = paren_reduce(d[k])
+                                       deps = use_reduce(deps, uselist=use)
+                                       deps = paren_normalize(deps)
+                                       deps = paren_enclose(deps)
+                               except portage.exception.InvalidDependString, e:
+                                       writemsg("%s: %s\n" % (k, str(e)),
+                                               noiselevel=-1)
+                                       del e
+                                       writemsg("!!! Invalid binary package: '%s'\n" % \
+                                               self.getname(cpv), noiselevel=-1)
+                                       self.dbapi.cpv_remove(cpv)
+                                       return
                                if deps:
                                        d[k] = deps
                                else:
index 9474c1f25e7b6fb645152b478d54779a0ccc031c..86975ae263680f4895c23bc7eef44116a183bdaa 100644 (file)
@@ -89,13 +89,23 @@ def paren_reduce(mystr,tokenize=1):
        """
        mylist = []
        while mystr:
-               if ("(" not in mystr) and (")" not in mystr):
+               left_paren = mystr.find("(")
+               has_left_paren = left_paren != -1
+               right_paren = mystr.find(")")
+               has_right_paren = right_paren != -1
+               if not has_left_paren and not has_right_paren:
                        freesec = mystr
                        subsec = None
                        tail = ""
                elif mystr[0] == ")":
                        return [mylist,mystr[1:]]
-               elif ("(" in mystr) and (mystr.index("(") < mystr.index(")")):
+               elif has_left_paren and not has_right_paren:
+                       raise portage.exception.InvalidDependString(
+                               "missing right parenthesis: '%s'" % mystr)
+               elif has_right_paren and not has_left_paren:
+                       raise portage.exception.InvalidDependString(
+                               "missing left parenthesis: '%s'" % mystr)
+               elif has_left_paren and left_paren < right_paren:
                        freesec,subsec = mystr.split("(",1)
                        subsec,tail = paren_reduce(subsec,tokenize)
                else: