summaryrefslogtreecommitdiffstats
path: root/src/dbus
diff options
context:
space:
mode:
authorSami Rosendahl <ext-sami.1.rosendahl@nokia.com>2011-11-23 10:03:26 +0200
committerQt by Nokia <qt-info@nokia.com>2011-11-23 19:14:12 +0100
commitb851c764a61c0de781ef3447230a0a6a3f4a0ed9 (patch)
treee027346c7289ecc2a74bf1dd54d6d3531c7911ad /src/dbus
parentc3160c84af3cb14c0edc5896be0ca637377e3805 (diff)
Fix stack overwrite in QDBusDemarshaller
QDBusArgument extraction operators and QDBusDemarshaller that implements the extraction do not check the type of the extracted value. Helper function template qIterGet in qdbusdemarshaller.cpp that is used for extracting basic data types only reserves space from the stack for the expected type as specified by client. If the actual type in the DBus parameter is larger stack will be overwritten in the helper function by at most 7 bytes (expected one byte, received dbus_uint_64_t of size 8 bytes). The fix always reserves space for the largest basic type dbus_uint64_t readable by dbus_message_iter_get_basic API. See also http://dbus.freedesktop.org/doc/api/html/group__DBusMessage.html#ga41c23a05e552d0574d04 Task-number: QTBUG-22735 Change-Id: I9aa25b279852ac8acc40199a39910ea4002042d7 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/dbus')
-rw-r--r--src/dbus/qdbusdemarshaller.cpp24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/dbus/qdbusdemarshaller.cpp b/src/dbus/qdbusdemarshaller.cpp
index d9bb5b5ead..4103552db1 100644
--- a/src/dbus/qdbusdemarshaller.cpp
+++ b/src/dbus/qdbusdemarshaller.cpp
@@ -48,10 +48,28 @@ QT_BEGIN_NAMESPACE
template <typename T>
static inline T qIterGet(DBusMessageIter *it)
{
- T t;
- q_dbus_message_iter_get_basic(it, &t);
+ // Use a union of expected and largest type q_dbus_message_iter_get_basic
+ // will return to ensure reading the wrong basic type does not result in
+ // stack overwrite
+ union {
+ // The value to be extracted
+ T t;
+ // Largest type that q_dbus_message_iter_get_basic will return
+ // according to dbus_message_iter_get_basic API documentation
+ dbus_uint64_t maxValue;
+ // A pointer to ensure no stack overwrite in case there is a platform
+ // where sizeof(void*) > sizeof(dbus_uint64_t)
+ void* ptr;
+ } value;
+
+ // Initialize the value in case a narrower type is extracted to it.
+ // Note that the result of extracting a narrower type in place of a wider
+ // one and vice-versa will be platform-dependent.
+ value.t = T();
+
+ q_dbus_message_iter_get_basic(it, &value);
q_dbus_message_iter_next(it);
- return t;
+ return value.t;
}
QDBusDemarshaller::~QDBusDemarshaller()