Mercurial > hg
comparison tests/test-parseindex2.py @ 20109:e57c532c3835 stable
parse_index2: fix crash on bad argument type (issue4110)
Passing a non-string to parsers.parse_index2() causes Mercurial to crash
instead of raising a TypeError (found on Mac OS X 10.8.5, Python 2.7.6):
import mercurial.parsers as parsers
parsers.parse_index2(0, 0)
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 parsers.so 0x000000010e071c59 _index_clearcaches + 73 (parsers.c:644)
1 parsers.so 0x000000010e06f2d5 index_dealloc + 21 (parsers.c:1767)
2 parsers.so 0x000000010e074e3b parse_index2 + 347 (parsers.c:1891)
3 org.python.python 0x000000010dda8b17 PyEval_EvalFrameEx + 9911
This happens because when arguments of the wrong type are passed to
parsers.parse_index2(), indexType's initialization function index_init() in
parsers.c leaves the indexObject instance in a state that indexType's
destructor function index_dealloc() cannot handle.
This patch moves enough of the indexObject initialization code inside
index_init() from after the argument validation code to before it.
This way, when bad arguments are passed to index_init(), the destructor
doesn't crash and the existing code to raise a TypeError works. This
patch also adds a test to check that a TypeError is raised.
author | Chris Jerdonek <chris.jerdonek@gmail.com> |
---|---|
date | Tue, 26 Nov 2013 16:14:22 -0800 |
parents | e22d6b1dec1d |
children | 21dafd8546d1 |
comparison
equal
deleted
inserted
replaced
20107:2ca325ea57fa | 20109:e57c532c3835 |
---|---|
96 def parse_index2(data, inline): | 96 def parse_index2(data, inline): |
97 index, chunkcache = parsers.parse_index2(data, inline) | 97 index, chunkcache = parsers.parse_index2(data, inline) |
98 return list(index), chunkcache | 98 return list(index), chunkcache |
99 | 99 |
100 def runtest() : | 100 def runtest() : |
101 # Check that parse_index2() raises TypeError on bad arguments. | |
102 try: | |
103 parse_index2(0, True) | |
104 except TypeError: | |
105 pass | |
106 else: | |
107 print "Expected to get TypeError." | |
108 | |
101 py_res_1 = py_parseindex(data_inlined, True) | 109 py_res_1 = py_parseindex(data_inlined, True) |
102 c_res_1 = parse_index2(data_inlined, True) | 110 c_res_1 = parse_index2(data_inlined, True) |
103 | 111 |
104 py_res_2 = py_parseindex(data_non_inlined, False) | 112 py_res_2 = py_parseindex(data_non_inlined, False) |
105 c_res_2 = parse_index2(data_non_inlined, False) | 113 c_res_2 = parse_index2(data_non_inlined, False) |