Commit 832bfe2e authored by Benjamin Peterson's avatar Benjamin Peterson

add a AST validator (closes #12575)

parent 450bb594
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
extern "C" { extern "C" {
#endif #endif
PyAPI_FUNC(int) PyAST_Validate(mod_ty);
PyAPI_FUNC(mod_ty) PyAST_FromNode( PyAPI_FUNC(mod_ty) PyAST_FromNode(
const node *n, const node *n,
PyCompilerFlags *flags, PyCompilerFlags *flags,
......
This diff is collapsed.
...@@ -10,6 +10,8 @@ What's New in Python 3.3 Alpha 1? ...@@ -10,6 +10,8 @@ What's New in Python 3.3 Alpha 1?
Core and Builtins Core and Builtins
----------------- -----------------
- Issue #12575: Validate user-generated AST before it is compiled.
- Make type(None), type(Ellipsis), and type(NotImplemented) callable. They - Make type(None), type(Ellipsis), and type(NotImplemented) callable. They
return the respective singleton instances. return the respective singleton instances.
......
This diff is collapsed.
...@@ -604,6 +604,10 @@ builtin_compile(PyObject *self, PyObject *args, PyObject *kwds) ...@@ -604,6 +604,10 @@ builtin_compile(PyObject *self, PyObject *args, PyObject *kwds)
PyArena_Free(arena); PyArena_Free(arena);
goto error; goto error;
} }
if (!PyAST_Validate(mod)) {
PyArena_Free(arena);
goto error;
}
result = (PyObject*)PyAST_CompileEx(mod, filename, result = (PyObject*)PyAST_CompileEx(mod, filename,
&cf, optimize, arena); &cf, optimize, arena);
PyArena_Free(arena); PyArena_Free(arena);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment