##// END OF EJS Templates
linelog: fix infinite loop vulnerability...
Jun Wu -
r38970:27a54096 default
parent child Browse files
Show More
@@ -360,13 +360,15 b' class linelog(object):'
360 def annotate(self, rev):
360 def annotate(self, rev):
361 pc = 1
361 pc = 1
362 lines = []
362 lines = []
363 # Sanity check: if len(lines) is longer than len(program), we
363 executed = 0
364 # Sanity check: if instructions executed exceeds len(program), we
364 # hit an infinite loop in the linelog program somehow and we
365 # hit an infinite loop in the linelog program somehow and we
365 # should stop.
366 # should stop.
366 while pc is not None and len(lines) < len(self._program):
367 while pc is not None and executed < len(self._program):
367 inst = self._program[pc]
368 inst = self._program[pc]
368 lastpc = pc
369 lastpc = pc
369 pc = inst.execute(rev, pc, lines.append)
370 pc = inst.execute(rev, pc, lines.append)
371 executed += 1
370 if pc is not None:
372 if pc is not None:
371 raise LineLogError(
373 raise LineLogError(
372 'Probably hit an infinite loop in linelog. Program:\n' +
374 'Probably hit an infinite loop in linelog. Program:\n' +
@@ -179,6 +179,15 b' class linelogtests(unittest.TestCase):'
179 ar = ll.annotate(rev)
179 ar = ll.annotate(rev)
180 self.assertEqual([(l.rev, l.linenum) for l in ar], lines)
180 self.assertEqual([(l.rev, l.linenum) for l in ar], lines)
181
181
182 def testinfinitebadprogram(self):
183 ll = linelog.linelog.fromdata(
184 b'\x00\x00\x00\x00\x00\x00\x00\x02' # header
185 b'\x00\x00\x00\x00\x00\x00\x00\x01' # JUMP to self
186 )
187 with self.assertRaises(linelog.LineLogError):
188 # should not be an infinite loop and raise
189 ll.annotate(1)
190
182 if __name__ == '__main__':
191 if __name__ == '__main__':
183 import silenttestrunner
192 import silenttestrunner
184 silenttestrunner.main(__name__)
193 silenttestrunner.main(__name__)
General Comments 0
You need to be logged in to leave comments. Login now