summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <smcv@collabora.com>2022-09-04 21:22:10 +0100
committerSimon McVittie <smcv@collabora.com>2022-09-06 14:52:12 +0100
commitf4d8c9f45dff584aec8df0993e1716390d57508c (patch)
tree4267c26ea312f7c19c3d3b4923b623809f076c82
parentf5e4724a3d7c5727ef5550ab95b3c47e290c1376 (diff)
downloaddbus-python-f4d8c9f45dff584aec8df0993e1716390d57508c.tar.gz
unixfd: Fix assertion failure constructing UnixFd for invalid fd
File descriptors are represented as the C int type, but only non-negative values represent a valid fd, with all negative values representing the absence of a fd (a NULL-like value). Previously, make_fd() accepted negative fds, but then UnixFd_tp_new would crash with an assertion failure. Instead, range-check the value according to the semantically valid range. If it isn't, raise the same error we previously raised for values that don't fit in an int. Signed-off-by: Simon McVittie <smcv@collabora.com>
-rw-r--r--dbus_bindings/unixfd.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/dbus_bindings/unixfd.c b/dbus_bindings/unixfd.c
index 63a2402..e515cd3 100644
--- a/dbus_bindings/unixfd.c
+++ b/dbus_bindings/unixfd.c
@@ -62,9 +62,9 @@ typedef struct {
} UnixFdObject;
/* Return values:
- * -2 - the long value overflows an int
+ * -2 - the long value is not plausible as a file descriptor
* -1 - Python failed producing a long (or in Python 2 an int)
- * 0 - success
+ * 0 - success (value might not *actually* be a fd, but it *could* be)
* 1 - arg is not a long (or in Python 2 an int)
*
* Or to summarize:
@@ -89,7 +89,7 @@ make_fd(PyObject *arg, int *fd)
return 1;
}
/* Check for int overflow. */
- if (fd_arg < INT_MIN || fd_arg > INT_MAX) {
+ if (fd_arg < 0 || fd_arg > INT_MAX) {
PyErr_Format(PyExc_ValueError, "int is outside fd range");
return -2;
}