5992: Crash when using a not allowed string as regex in Person with name filter

svn: r20364
This commit is contained in:
Benny Malengier 2012-09-11 09:28:55 +00:00
parent 86a0607628
commit f1f1f7cbbe
2 changed files with 32 additions and 27 deletions

View File

@ -95,32 +95,36 @@ class HasNameOf(Rule):
if not self.patr: if not self.patr:
valpatr = 1 valpatr = 1
if self.regular_expression: if self.regular_expression:
if self.firstn and not re.match(self.firstn, name.get_first_name(), re.I|re.U|re.L): try:
val = 0 if self.firstn and not re.match(self.firstn, name.get_first_name(), re.I|re.U|re.L):
elif self.lastn and not re.match(self.lastn, name.get_surname(), re.I|re.U|re.L): val = 0
val = 0 elif self.lastn and not re.match(self.lastn, name.get_surname(), re.I|re.U|re.L):
elif self.suffix and not re.match(self.suffix, name.get_suffix(), re.I|re.U|re.L): val = 0
val = 0 elif self.suffix and not re.match(self.suffix, name.get_suffix(), re.I|re.U|re.L):
elif self.title and not re.match(self.title, name.get_title(), re.I|re.U|re.L): val = 0
val = 0 elif self.title and not re.match(self.title, name.get_title(), re.I|re.U|re.L):
elif self.calln and not re.match(self.calln, name.get_call_name(), re.I|re.U|re.L): val = 0
val = 0 elif self.calln and not re.match(self.calln, name.get_call_name(), re.I|re.U|re.L):
elif self.nick and not re.match(self.nick, name.get_nick_name(), re.I|re.U|re.L): val = 0
val = 0 elif self.nick and not re.match(self.nick, name.get_nick_name(), re.I|re.U|re.L):
elif self.famnick and not re.match(self.famnick, name.get_family_nick_name(), re.I|re.U|re.L): val = 0
val = 0 elif self.famnick and not re.match(self.famnick, name.get_family_nick_name(), re.I|re.U|re.L):
else: val = 0
#obtain surnames else:
for surn in name.get_surname_list(): #obtain surnames
if self.prefix and re.match(self.prefix, surn.get_prefix(), re.I|re.U|re.L): for surn in name.get_surname_list():
valpref = 1 if self.prefix and re.match(self.prefix, surn.get_prefix(), re.I|re.U|re.L):
if self.surn and re.match(self.surn, surn.get_surname(), re.I|re.U|re.L): valpref = 1
valsurn = 1 if self.surn and re.match(self.surn, surn.get_surname(), re.I|re.U|re.L):
if self.con and re.match(self.con, surn.get_connector(), re.I|re.U|re.L): valsurn = 1
valcon = 1 if self.con and re.match(self.con, surn.get_connector(), re.I|re.U|re.L):
if self.patr and surn.get_origintype().value == NameOriginType.PATRONYMIC \ valcon = 1
and re.match(self.patr, surn.get_surname(), re.I|re.U|re.L): if self.patr and surn.get_origintype().value == NameOriginType.PATRONYMIC \
valpatr = 1 and re.match(self.patr, surn.get_surname(), re.I|re.U|re.L):
valpatr = 1
except re.error:
#indicate error in the pattern by matching everyone
return True
else: else:
if self.firstn and name.get_first_name().upper().find(self.firstn) == -1: if self.firstn and name.get_first_name().upper().find(self.firstn) == -1:
val = 0 val = 0

View File

@ -54,7 +54,8 @@ class RegExpName(Rule):
try: try:
self.match = re.compile(list[0],re.I|re.U|re.L) self.match = re.compile(list[0],re.I|re.U|re.L)
except: except re.error:
#indicate error by matching everyone
self.match = re.compile('') self.match = re.compile('')
def apply(self,db,person): def apply(self,db,person):