From fafe2c234f91daac4f22bbab66f2df917db94465 Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Sat, 20 Jun 2020 11:23:17 -0700 Subject: [PATCH 1/2] Use the fildes converter for fd to please Coverity. there are a bunch of other fd: int uses in this file, I expect many if not all of them would be better off using the fildes converter. This particular one was flagged by Coverity as it presumably flags fpathconf as not accepting negative fds. I'd expect the other fd's to have been flagged as well otherwise. --- Modules/clinic/posixmodule.c.h | 5 ++--- Modules/posixmodule.c | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h index ff439ee47c3930f..b691cfbc6edef3d 100644 --- a/Modules/clinic/posixmodule.c.h +++ b/Modules/clinic/posixmodule.c.h @@ -6803,8 +6803,7 @@ os_fpathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs) if (!_PyArg_CheckPositional("fpathconf", nargs, 2, 2)) { goto exit; } - fd = _PyLong_AsInt(args[0]); - if (fd == -1 && PyErr_Occurred()) { + if (!fildes_converter(args[0], &fd)) { goto exit; } if (!conv_path_confname(args[1], &name)) { @@ -8877,4 +8876,4 @@ os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t na #ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF #endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */ -/*[clinic end generated code: output=767780ea3beacf34 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=d7c1212a94613496 input=a9049054013a1b77]*/ diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 79779bfdeafd3ad..a411f28987ee717 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -10988,7 +10988,7 @@ conv_path_confname(PyObject *arg, int *valuep) /*[clinic input] os.fpathconf -> long - fd: int + fd: fildes name: path_confname / @@ -10999,7 +10999,7 @@ If there is no limit, return -1. static long os_fpathconf_impl(PyObject *module, int fd, int name) -/*[clinic end generated code: output=d5b7042425fc3e21 input=5942a024d3777810]*/ +/*[clinic end generated code: output=d5b7042425fc3e21 input=5b8d2471cfaae186]*/ { long limit; From 29bc1a207b4396237c0d48393ec8ba0d27b18205 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sat, 20 Jun 2020 18:37:34 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NEWS.d/next/Library/2020-06-20-18-37-29.bpo-41056.d9v_uL.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2020-06-20-18-37-29.bpo-41056.d9v_uL.rst diff --git a/Misc/NEWS.d/next/Library/2020-06-20-18-37-29.bpo-41056.d9v_uL.rst b/Misc/NEWS.d/next/Library/2020-06-20-18-37-29.bpo-41056.d9v_uL.rst new file mode 100644 index 000000000000000..ddcc1102d5ed723 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-06-20-18-37-29.bpo-41056.d9v_uL.rst @@ -0,0 +1 @@ +Invalid file descriptor values are now prevented from being passed to os.fpathconf. (discovered by Coverity) \ No newline at end of file