From 45a30af109f69a81576b87ea775863ba12d55316 Mon Sep 17 00:00:00 2001 From: Brandt Bucher Date: Thu, 27 Jun 2019 09:10:57 -0700 Subject: [PATCH] closes bpo-37420: Handle errors during iteration in os.sched_setaffinity. (GH-14414) --- Lib/test/test_posix.py | 1 + .../next/Library/2019-06-26-22-25-05.bpo-37420.CxFJ09.rst | 2 ++ Modules/posixmodule.c | 3 +++ 3 files changed, 6 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2019-06-26-22-25-05.bpo-37420.CxFJ09.rst diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index afa1398d4ed..9bdd2848afc 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -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 index 00000000000..dea1a292501 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-06-26-22-25-05.bpo-37420.CxFJ09.rst @@ -0,0 +1,2 @@ +:func:`os.sched_setaffinity` now correctly handles errors that arise during iteration over its ``mask`` argument. +Patch by Brandt Bucher. \ No newline at end of file diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 5f17fce1a71..197607c9cb1 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -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)) {