Skip to content

Commit 644bef7

Browse files
committed
Issue #9128: Fix validation of class decorators in parser module.
1 parent e9123ef commit 644bef7

3 files changed

Lines changed: 19 additions & 8 deletions

File tree

Lib/test/test_parser.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,14 @@ def test_function_defs(self):
156156

157157
def test_class_defs(self):
158158
self.check_suite("class foo():pass")
159+
self.check_suite("@class_decorator\n"
160+
"class foo():pass")
161+
self.check_suite("@class_decorator(arg)\n"
162+
"class foo():pass")
163+
self.check_suite("@decorator1\n"
164+
"@decorator2\n"
165+
"class foo():pass")
166+
159167

160168
def test_import_from_statement(self):
161169
self.check_suite("from sys.path import *")

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ C-API
8181
Library
8282
-------
8383

84+
- Issue #9128: Fix validation of class decorators in parser module.
85+
8486
- Issue #7673: Fix security vulnerability (CVE-2010-2089) in the audioop
8587
module, ensure that the input string length is a multiple of the frame size
8688

Modules/parsermodule.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2679,14 +2679,15 @@ validate_funcdef(node *tree)
26792679
static int
26802680
validate_decorated(node *tree)
26812681
{
2682-
int nch = NCH(tree);
2683-
int ok = (validate_ntype(tree, decorated)
2684-
&& (nch == 2)
2685-
&& validate_decorators(RCHILD(tree, -2))
2686-
&& (validate_funcdef(RCHILD(tree, -1))
2687-
|| validate_class(RCHILD(tree, -1)))
2688-
);
2689-
return ok;
2682+
int nch = NCH(tree);
2683+
int ok = (validate_ntype(tree, decorated)
2684+
&& (nch == 2)
2685+
&& validate_decorators(RCHILD(tree, -2)));
2686+
if (TYPE(RCHILD(tree, -1)) == funcdef)
2687+
ok = ok && validate_funcdef(RCHILD(tree, -1));
2688+
else
2689+
ok = ok && validate_class(RCHILD(tree, -1));
2690+
return ok;
26902691
}
26912692

26922693
static int

0 commit comments

Comments
 (0)