summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-07-16 20:26:05 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2013-07-16 20:26:05 (GMT)
commit1e53bbacedaed883104454693c29d1ad31f5029b (patch)
treee4fc2ec54fe409dd3e50fbd7ac756a43b103bbf8 /Python
parent1b63493ed18a93201ad0c09bfc849a13d9f01632 (diff)
downloadcpython-1e53bbacedaed883104454693c29d1ad31f5029b.zip
cpython-1e53bbacedaed883104454693c29d1ad31f5029b.tar.gz
cpython-1e53bbacedaed883104454693c29d1ad31f5029b.tar.bz2
Issue #18408: handle PySys_GetObject() failure, raise a RuntimeError
Diffstat (limited to 'Python')
-rw-r--r--Python/bltinmodule.c5
-rw-r--r--Python/import.c14
2 files changed, 13 insertions, 6 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 949f029..06d71f7 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -1550,6 +1550,11 @@ builtin_print(PyObject *self, PyObject *args, PyObject *kwds)
return NULL;
if (file == NULL || file == Py_None) {
file = PySys_GetObject("stdout");
+ if (file == NULL) {
+ PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");
+ return NULL;
+ }
+
/* sys.stdout may be None when FILE* stdout isn't connected */
if (file == Py_None)
Py_RETURN_NONE;
diff --git a/Python/import.c b/Python/import.c
index 2e5d205..a1c0aee 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -85,8 +85,10 @@ _PyImportZip_Init(void)
int err = 0;
path_hooks = PySys_GetObject("path_hooks");
- if (path_hooks == NULL)
+ if (path_hooks == NULL) {
+ PyErr_SetString(PyExc_RuntimeError, "unable to get sys.path_hooks");
goto error;
+ }
if (Py_VerboseFlag)
PySys_WriteStderr("# installing zipimport hook\n");
@@ -944,11 +946,11 @@ PyAPI_FUNC(PyObject *)
PyImport_GetImporter(PyObject *path) {
PyObject *importer=NULL, *path_importer_cache=NULL, *path_hooks=NULL;
- if ((path_importer_cache = PySys_GetObject("path_importer_cache"))) {
- if ((path_hooks = PySys_GetObject("path_hooks"))) {
- importer = get_path_importer(path_importer_cache,
- path_hooks, path);
- }
+ path_importer_cache = PySys_GetObject("path_importer_cache");
+ path_hooks = PySys_GetObject("path_hooks");
+ if (path_importer_cache != NULL && path_hooks != NULL) {
+ importer = get_path_importer(path_importer_cache,
+ path_hooks, path);
}
Py_XINCREF(importer); /* get_path_importer returns a borrowed reference */
return importer;