summaryrefslogtreecommitdiff
path: root/Python/compile.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-08-29 15:47:44 +0300
committerGitHub <noreply@github.com>2017-08-29 15:47:44 +0300
commit265fcc5fc25d65afb33fda480c603f1e974e374e (patch)
tree7bb91548c80be5ddf5119624bf6acee6d672ed6c /Python/compile.c
parentba7d7365215d791025d1efd25393c91404f2cfc8 (diff)
downloadcpython-git-265fcc5fc25d65afb33fda480c603f1e974e374e.tar.gz
bpo-31286, bpo-30024: Fixed stack usage in absolute imports with (#3217)
binding a submodule to a name.
Diffstat (limited to 'Python/compile.c')
-rw-r--r--Python/compile.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/Python/compile.c b/Python/compile.c
index 78e797a2c3..e547c2fd59 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -2673,28 +2673,34 @@ compiler_import_as(struct compiler *c, identifier name, identifier asname)
If there is a dot in name, we need to split it and emit a
IMPORT_FROM for each name.
*/
- Py_ssize_t dot = PyUnicode_FindChar(name, '.', 0,
- PyUnicode_GET_LENGTH(name), 1);
+ Py_ssize_t len = PyUnicode_GET_LENGTH(name);
+ Py_ssize_t dot = PyUnicode_FindChar(name, '.', 0, len, 1);
if (dot == -2)
return 0;
if (dot != -1) {
/* Consume the base module name to get the first attribute */
- Py_ssize_t pos = dot + 1;
- while (dot != -1) {
+ while (1) {
+ Py_ssize_t pos = dot + 1;
PyObject *attr;
- dot = PyUnicode_FindChar(name, '.', pos,
- PyUnicode_GET_LENGTH(name), 1);
+ dot = PyUnicode_FindChar(name, '.', pos, len, 1);
if (dot == -2)
return 0;
- attr = PyUnicode_Substring(name, pos,
- (dot != -1) ? dot :
- PyUnicode_GET_LENGTH(name));
+ attr = PyUnicode_Substring(name, pos, (dot != -1) ? dot : len);
if (!attr)
return 0;
ADDOP_O(c, IMPORT_FROM, attr, names);
Py_DECREF(attr);
- pos = dot + 1;
+ if (dot == -1) {
+ break;
+ }
+ ADDOP(c, ROT_TWO);
+ ADDOP(c, POP_TOP);
}
+ if (!compiler_nameop(c, asname, Store)) {
+ return 0;
+ }
+ ADDOP(c, POP_TOP);
+ return 1;
}
return compiler_nameop(c, asname, Store);
}