Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
a79f4c21
Commit
a79f4c21
authored
Apr 19, 2017
by
Serhiy Storchaka
Committed by
GitHub
Apr 19, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-30070: Fixed leaks and crashes in errors handling in the parser module. (#1131)
parent
d90045f3
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
162 additions
and
52 deletions
+162
-52
Lib/test/test_parser.py
Lib/test/test_parser.py
+81
-0
Misc/NEWS
Misc/NEWS
+2
-0
Modules/parsermodule.c
Modules/parsermodule.c
+79
-52
No files found.
Lib/test/test_parser.py
View file @
a79f4c21
import
copy
import
parser
import
pickle
import
unittest
import
operator
import
struct
...
...
@@ -424,6 +426,52 @@ class IllegalSyntaxTestCase(unittest.TestCase):
# not even remotely valid:
self
.
check_bad_tree
((
1
,
2
,
3
),
"<junk>"
)
def
test_illegal_terminal
(
self
):
tree
=
\
(
257
,
(
269
,
(
270
,
(
271
,
(
277
,
(
1
,))),
(
4
,
''
))),
(
4
,
''
),
(
0
,
''
))
self
.
check_bad_tree
(
tree
,
"too small items in terminal node"
)
tree
=
\
(
257
,
(
269
,
(
270
,
(
271
,
(
277
,
(
1
,
b'pass'
))),
(
4
,
''
))),
(
4
,
''
),
(
0
,
''
))
self
.
check_bad_tree
(
tree
,
"non-string second item in terminal node"
)
tree
=
\
(
257
,
(
269
,
(
270
,
(
271
,
(
277
,
(
1
,
'pass'
,
'0'
,
0
))),
(
4
,
''
))),
(
4
,
''
),
(
0
,
''
))
self
.
check_bad_tree
(
tree
,
"non-integer third item in terminal node"
)
tree
=
\
(
257
,
(
269
,
(
270
,
(
271
,
(
277
,
(
1
,
'pass'
,
0
,
0
))),
(
4
,
''
))),
(
4
,
''
),
(
0
,
''
))
self
.
check_bad_tree
(
tree
,
"too many items in terminal node"
)
def
test_illegal_yield_1
(
self
):
# Illegal yield statement: def f(): return 1; yield 1
tree
=
\
...
...
@@ -628,6 +676,24 @@ class IllegalSyntaxTestCase(unittest.TestCase):
(
4
,
''
),
(
0
,
''
))
self
.
check_bad_tree
(
tree
,
"from import fred"
)
def
test_illegal_encoding
(
self
):
# Illegal encoding declaration
tree
=
\
(
339
,
(
257
,
(
0
,
''
)))
self
.
check_bad_tree
(
tree
,
"missed encoding"
)
tree
=
\
(
339
,
(
257
,
(
0
,
''
)),
b'iso-8859-1'
)
self
.
check_bad_tree
(
tree
,
"non-string encoding"
)
tree
=
\
(
339
,
(
257
,
(
0
,
''
)),
'
\
udcff
'
)
with
self
.
assertRaises
(
UnicodeEncodeError
):
parser
.
sequence2st
(
tree
)
class
CompileTestCase
(
unittest
.
TestCase
):
...
...
@@ -772,6 +838,21 @@ class STObjectTestCase(unittest.TestCase):
self
.
assertRaises
(
TypeError
,
operator
.
lt
,
st1
,
1815
)
self
.
assertRaises
(
TypeError
,
operator
.
gt
,
b'waterloo'
,
st2
)
def
test_copy_pickle
(
self
):
sts
=
[
parser
.
expr
(
'2 + 3'
),
parser
.
suite
(
'x = 2; y = x + 3'
),
parser
.
expr
(
'list(x**3 for x in range(20))'
)
]
for
st
in
sts
:
st_copy
=
copy
.
copy
(
st
)
self
.
assertEqual
(
st_copy
.
totuple
(),
st
.
totuple
())
st_copy
=
copy
.
deepcopy
(
st
)
self
.
assertEqual
(
st_copy
.
totuple
(),
st
.
totuple
())
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
st_copy
=
pickle
.
loads
(
pickle
.
dumps
(
st
,
proto
))
self
.
assertEqual
(
st_copy
.
totuple
(),
st
.
totuple
())
check_sizeof
=
support
.
check_sizeof
@
support
.
cpython_only
...
...
Misc/NEWS
View file @
a79f4c21
...
...
@@ -313,6 +313,8 @@ Extension Modules
Library
-------
- bpo-30070: Fixed leaks and crashes in errors handling in the parser module.
- bpo-22352: Column widths in the output of dis.dis() are now adjusted for
large line numbers and instruction offsets.
...
...
Modules/parsermodule.c
View file @
a79f4c21
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment