]> granicus.if.org Git - python/commitdiff
closes bpo-37420: Handle errors during iteration in os.sched_setaffinity. (GH-14414)
authorBrandt Bucher <brandtbucher@gmail.com>
Thu, 27 Jun 2019 16:10:57 +0000 (09:10 -0700)
committerBenjamin Peterson <benjamin@python.org>
Thu, 27 Jun 2019 16:10:57 +0000 (09:10 -0700)
Lib/test/test_posix.py
Misc/NEWS.d/next/Library/2019-06-26-22-25-05.bpo-37420.CxFJ09.rst [new file with mode: 0644]
Modules/posixmodule.c

index afa1398d4edc0d0c98e440295091b24b5cd4b394..9bdd2848afc81b87ed2e11e64b67931ef96bfb69 100644 (file)
@@ -1368,6 +1368,7 @@ class PosixTester(unittest.TestCase):
         self.assertEqual(posix.sched_getaffinity(0), mask)
         self.assertRaises(OSError, posix.sched_setaffinity, 0, [])
         self.assertRaises(ValueError, posix.sched_setaffinity, 0, [-10])
+        self.assertRaises(ValueError, posix.sched_setaffinity, 0, map(int, "0X"))
         self.assertRaises(OverflowError, posix.sched_setaffinity, 0, [1<<128])
         self.assertRaises(OSError, posix.sched_setaffinity, -1, mask)
 
diff --git a/Misc/NEWS.d/next/Library/2019-06-26-22-25-05.bpo-37420.CxFJ09.rst b/Misc/NEWS.d/next/Library/2019-06-26-22-25-05.bpo-37420.CxFJ09.rst
new file mode 100644 (file)
index 0000000..dea1a29
--- /dev/null
@@ -0,0 +1,2 @@
+:func:`os.sched_setaffinity` now correctly handles errors that arise during iteration over its ``mask`` argument.\r
+Patch by Brandt Bucher.
\ No newline at end of file
index 5f17fce1a717caa59c4cce9f3889ed027d2d7578..197607c9cb101c10a1e03c3ab1aa355ce0ae9ea4 100644 (file)
@@ -6413,6 +6413,9 @@ os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask)
         }
         CPU_SET_S(cpu, setsize, cpu_set);
     }
+    if (PyErr_Occurred()) {
+        goto error;
+    }
     Py_CLEAR(iterator);
 
     if (sched_setaffinity(pid, setsize, cpu_set)) {