]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-35742: Fix test_envar_unimportable in test_builtin. (GH-11561)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 15 Jan 2019 11:45:57 +0000 (03:45 -0800)
committerGitHub <noreply@github.com>
Tue, 15 Jan 2019 11:45:57 +0000 (03:45 -0800)
Handle the case of an empty module name in PYTHONBREAKPOINT.

Fixes a regression introduced in bpo-34756.
(cherry picked from commit 3607ef43c4a1a24d44f39ff54a77fc0af5bfa09a)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Lib/test/test_builtin.py
Python/sysmodule.c

index 7c9768a337bbb022379a6c2682f82241d7c10abc..c3f04ec7447c6ede04cca98ebecfa2bd7cee141a 100644 (file)
@@ -1601,6 +1601,7 @@ class TestBreakpoint(unittest.TestCase):
     def test_envar_unimportable(self):
         for envar in (
                 '.', '..', '.foo', 'foo.', '.int', 'int.',
+                '.foo.bar', '..foo.bar', '/./',
                 'nosuchbuiltin',
                 'nosuchmodule.nosuchcallable',
                 ):
index 75e4f4bf294f22499f63b966109f215487855025..cdc2edf038a13967705f824e25f1291d3cc28a42 100644 (file)
@@ -134,11 +134,14 @@ sys_breakpointhook(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyOb
         modulepath = PyUnicode_FromString("builtins");
         attrname = envar;
     }
-    else {
+    else if (last_dot != envar) {
         /* Split on the last dot; */
         modulepath = PyUnicode_FromStringAndSize(envar, last_dot - envar);
         attrname = last_dot + 1;
     }
+    else {
+        goto warn;
+    }
     if (modulepath == NULL) {
         PyMem_RawFree(envar);
         return NULL;
@@ -156,27 +159,29 @@ sys_breakpointhook(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyOb
     Py_DECREF(fromlist);
 
     if (module == NULL) {
-        goto error;
+        if (PyErr_ExceptionMatches(PyExc_ImportError)) {
+            goto warn;
+        }
+        PyMem_RawFree(envar);
+        return NULL;
     }
 
     PyObject *hook = PyObject_GetAttrString(module, attrname);
     Py_DECREF(module);
 
     if (hook == NULL) {
-        goto error;
+        if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
+            goto warn;
+        }
+        PyMem_RawFree(envar);
+        return NULL;
     }
     PyMem_RawFree(envar);
     PyObject *retval = _PyObject_FastCallKeywords(hook, args, nargs, keywords);
     Py_DECREF(hook);
     return retval;
 
-  error:
-    if (!PyErr_ExceptionMatches(PyExc_ImportError)
-        && !PyErr_ExceptionMatches(PyExc_AttributeError))
-    {
-        PyMem_RawFree(envar);
-        return NULL;
-    }
+  warn:
     /* If any of the imports went wrong, then warn and ignore. */
     PyErr_Clear();
     int status = PyErr_WarnFormat(