From c69b0f404b40e56e05c9ab443353cb7332c61183 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Mon, 11 Jun 2007 02:49:15 +0000 Subject: [PATCH] For bug #181355, detect parenthesis mismatch in paren_reduce(), raise an InvalidDependString exception, and make sure that all callers handle the exception properly. (trunk r6795:6797) svn path=/main/branches/2.1.2/; revision=6798 --- bin/repoman | 4 ++++ pym/portage.py | 16 ++++++++++++---- pym/portage_dep.py | 11 +++++++++-- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/bin/repoman b/bin/repoman index 3a939d9ac..c033a0d44 100755 --- a/bin/repoman +++ b/bin/repoman @@ -1129,6 +1129,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) diff --git a/pym/portage.py b/pym/portage.py index c59edb941..ee7b9c4a0 100644 --- a/pym/portage.py +++ b/pym/portage.py @@ -3092,9 +3092,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] @@ -4398,7 +4403,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() diff --git a/pym/portage_dep.py b/pym/portage_dep.py index b87058f7f..a8007857e 100644 --- a/pym/portage_dep.py +++ b/pym/portage_dep.py @@ -69,13 +69,20 @@ 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_left_paren and left_paren < right_paren: freesec,subsec = mystr.split("(",1) subsec,tail = paren_reduce(subsec,tokenize) else: -- 2.26.2