Commit 0feaf8f0 authored by Guido van Rossum's avatar Guido van Rossum

First part of SF patch #416704: More robust freeze, by Toby Dickenson.

This fixes the behavior reported by SF bug #404545, where a file
x.y.py could be imported by the statement "import x.y" when there's a
frozen package x (I believe even if x.y also exists as a frozen
module).
parent bc28bb67
...@@ -877,15 +877,15 @@ find_module(char *realname, PyObject *path, char *buf, size_t buflen, ...@@ -877,15 +877,15 @@ find_module(char *realname, PyObject *path, char *buf, size_t buflen,
char name[MAXPATHLEN+1]; char name[MAXPATHLEN+1];
if (strlen(realname) > MAXPATHLEN) { if (strlen(realname) > MAXPATHLEN) {
PyErr_SetString(PyExc_OverflowError, "module name is too long"); PyErr_SetString(PyExc_OverflowError,
"module name is too long");
return NULL; return NULL;
} }
strcpy(name, realname); strcpy(name, realname);
if (path != NULL && PyString_Check(path)) { if (path != NULL && PyString_Check(path)) {
/* Submodule of "frozen" package: /* The only type of submodule allowed inside a "frozen"
Set name to the fullname, path to NULL package are other frozen modules or packages. */
and continue as "usual" */
if (PyString_Size(path) + 1 + strlen(name) >= (size_t)buflen) { if (PyString_Size(path) + 1 + strlen(name) >= (size_t)buflen) {
PyErr_SetString(PyExc_ImportError, PyErr_SetString(PyExc_ImportError,
"full frozen module name too long"); "full frozen module name too long");
...@@ -895,7 +895,13 @@ find_module(char *realname, PyObject *path, char *buf, size_t buflen, ...@@ -895,7 +895,13 @@ find_module(char *realname, PyObject *path, char *buf, size_t buflen,
strcat(buf, "."); strcat(buf, ".");
strcat(buf, name); strcat(buf, name);
strcpy(name, buf); strcpy(name, buf);
path = NULL; if (find_frozen(name) != NULL) {
strcpy(buf, name);
return &fd_frozen;
}
PyErr_Format(PyExc_ImportError,
"No frozen submodule named %.200s", name);
return NULL;
} }
if (path == NULL) { if (path == NULL) {
if (is_builtin(name)) { if (is_builtin(name)) {
...@@ -1441,6 +1447,12 @@ get_frozen_object(char *name) ...@@ -1441,6 +1447,12 @@ get_frozen_object(char *name)
name); name);
return NULL; return NULL;
} }
if (p->code == NULL) {
PyErr_Format(PyExc_ImportError,
"Excluded frozen object named %.200s",
name);
return NULL;
}
size = p->size; size = p->size;
if (size < 0) if (size < 0)
size = -size; size = -size;
...@@ -1463,6 +1475,12 @@ PyImport_ImportFrozenModule(char *name) ...@@ -1463,6 +1475,12 @@ PyImport_ImportFrozenModule(char *name)
if (p == NULL) if (p == NULL)
return 0; return 0;
if (p->code == NULL) {
PyErr_Format(PyExc_ImportError,
"Excluded frozen object named %.200s",
name);
return -1;
}
size = p->size; size = p->size;
ispackage = (size < 0); ispackage = (size < 0);
if (ispackage) if (ispackage)
......
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