From: Mark J Hewitt Date: Mon, 11 Aug 2014 10:36:19 +0000 (+0100) Subject: Assume FS_IOC_GETFLAGS may trash output on error X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=318870668e54342a47a85022c4b8e34febc14ebf;p=packages%2Fb%2Fbup.git Assume FS_IOC_GETFLAGS may trash output on error Don't assert that the attr value is reasonable (<= UINT_MAX) when FS_IOC_GETFLAGS returns an error, because it may change the the value to something invalid in that situation. This has been observed to occur when, for example, the underlying filesystem does not support the operation, Signed-off-by: Mark J Hewitt [rlb@defaultvalue.org: adjust commit message] Reviewed-by: Rob Browning Tested-by: Rob Browning --- diff --git a/lib/bup/_helpers.c b/lib/bup/_helpers.c index 65a8b6b..9082dca 100644 --- a/lib/bup/_helpers.c +++ b/lib/bup/_helpers.c @@ -842,14 +842,13 @@ static PyObject *bup_get_linux_file_attr(PyObject *self, PyObject *args) attr = 0; // Handle int/long mismatch (see above) rc = ioctl(fd, FS_IOC_GETFLAGS, &attr); - assert(attr <= UINT_MAX); // Kernel type is actually int if (rc == -1) { close(fd); return PyErr_SetFromErrnoWithFilename(PyExc_OSError, path); } - close(fd); + assert(attr <= UINT_MAX); // Kernel type is actually int return PyLong_FromUnsignedLong(attr); } #endif /* def BUP_HAVE_FILE_ATTRS */