diff options
author | Jannis Voelker <jannis.voelker@basyskom.com> | 2018-06-19 12:07:32 +0200 |
---|---|---|
committer | Jannis Völker <jannis.voelker@basyskom.com> | 2018-07-03 06:44:18 +0000 |
commit | ec8595986aeb73b030c50dfa3596e3559222c388 (patch) | |
tree | 6fad98f01f8d3fce70f168f5c5fc5579284e925c | |
parent | 7523ab354e38ab6d0aba3e5fe8f24c9c4d1ab032 (diff) |
Check client before dispatching a request from the node
A node object can outlive the client object it was created by.
If the client pointer is not checked first, a method call from
such a node would result in a segmentation fault.
Change-Id: I6b0581435b4e5460195a83c8afa307f2158282d9
Reviewed-by: Rainer Keller <Rainer.Keller@qt.io>
-rw-r--r-- | src/plugins/opcua/open62541/qopen62541node.cpp | 24 | ||||
-rw-r--r-- | src/plugins/opcua/uacpp/quacppnode.cpp | 24 |
2 files changed, 48 insertions, 0 deletions
diff --git a/src/plugins/opcua/open62541/qopen62541node.cpp b/src/plugins/opcua/open62541/qopen62541node.cpp index 9285eba..868c36a 100644 --- a/src/plugins/opcua/open62541/qopen62541node.cpp +++ b/src/plugins/opcua/open62541/qopen62541node.cpp @@ -64,6 +64,9 @@ QOpen62541Node::~QOpen62541Node() bool QOpen62541Node::readAttributes(QOpcUa::NodeAttributes attr, const QString &indexRange) { + if (!m_client) + return false; + UA_NodeId tempId; UA_NodeId_copy(&m_nodeId, &tempId); return QMetaObject::invokeMethod(m_client->m_backend, "readAttributes", @@ -76,6 +79,9 @@ bool QOpen62541Node::readAttributes(QOpcUa::NodeAttributes attr, const QString & bool QOpen62541Node::enableMonitoring(QOpcUa::NodeAttributes attr, const QOpcUaMonitoringParameters &settings) { + if (!m_client) + return false; + UA_NodeId tempId; UA_NodeId_copy(&m_nodeId, &tempId); return QMetaObject::invokeMethod(m_client->m_backend, "enableMonitoring", @@ -88,6 +94,9 @@ bool QOpen62541Node::enableMonitoring(QOpcUa::NodeAttributes attr, const QOpcUaM bool QOpen62541Node::disableMonitoring(QOpcUa::NodeAttributes attr) { + if (!m_client) + return false; + return QMetaObject::invokeMethod(m_client->m_backend, "disableMonitoring", Qt::QueuedConnection, Q_ARG(uintptr_t, reinterpret_cast<uintptr_t>(this)), @@ -96,6 +105,9 @@ bool QOpen62541Node::disableMonitoring(QOpcUa::NodeAttributes attr) bool QOpen62541Node::modifyMonitoring(QOpcUa::NodeAttribute attr, QOpcUaMonitoringParameters::Parameter item, const QVariant &value) { + if (!m_client) + return false; + return QMetaObject::invokeMethod(m_client->m_backend, "modifyMonitoring", Qt::QueuedConnection, Q_ARG(uintptr_t, reinterpret_cast<uintptr_t>(this)), @@ -111,6 +123,9 @@ QString QOpen62541Node::nodeId() const bool QOpen62541Node::browseChildren(QOpcUa::ReferenceTypeId referenceType, QOpcUa::NodeClasses nodeClassMask) { + if (!m_client) + return false; + UA_NodeId tempId; UA_NodeId_copy(&m_nodeId, &tempId); return QMetaObject::invokeMethod(m_client->m_backend, "browseChildren", @@ -123,6 +138,9 @@ bool QOpen62541Node::browseChildren(QOpcUa::ReferenceTypeId referenceType, QOpcU bool QOpen62541Node::writeAttribute(QOpcUa::NodeAttribute attribute, const QVariant &value, QOpcUa::Types type, const QString &indexRange) { + if (!m_client) + return false; + UA_NodeId tempId; UA_NodeId_copy(&m_nodeId, &tempId); return QMetaObject::invokeMethod(m_client->m_backend, "writeAttribute", @@ -137,6 +155,9 @@ bool QOpen62541Node::writeAttribute(QOpcUa::NodeAttribute attribute, const QVari bool QOpen62541Node::writeAttributes(const QOpcUaNode::AttributeMap &toWrite, QOpcUa::Types valueAttributeType) { + if (!m_client) + return false; + UA_NodeId tempId; UA_NodeId_copy(&m_nodeId, &tempId); return QMetaObject::invokeMethod(m_client->m_backend, "writeAttributes", @@ -149,6 +170,9 @@ bool QOpen62541Node::writeAttributes(const QOpcUaNode::AttributeMap &toWrite, QO bool QOpen62541Node::callMethod(const QString &methodNodeId, const QVector<QOpcUa::TypedVariant> &args) { + if (!m_client) + return false; + UA_NodeId obj; UA_NodeId_copy(&m_nodeId, &obj); return QMetaObject::invokeMethod(m_client->m_backend, "callMethod", diff --git a/src/plugins/opcua/uacpp/quacppnode.cpp b/src/plugins/opcua/uacpp/quacppnode.cpp index 920b966..dec71a4 100644 --- a/src/plugins/opcua/uacpp/quacppnode.cpp +++ b/src/plugins/opcua/uacpp/quacppnode.cpp @@ -46,6 +46,9 @@ QUACppNode::~QUACppNode() bool QUACppNode::readAttributes(QOpcUa::NodeAttributes attr, const QString &indexRange) { + if (!m_client) + return false; + return QMetaObject::invokeMethod(m_client->m_backend, "readAttributes", Qt::QueuedConnection, Q_ARG(uintptr_t, reinterpret_cast<uintptr_t>(this)), @@ -56,6 +59,9 @@ bool QUACppNode::readAttributes(QOpcUa::NodeAttributes attr, const QString &inde bool QUACppNode::enableMonitoring(QOpcUa::NodeAttributes attr, const QOpcUaMonitoringParameters &settings) { + if (!m_client) + return false; + return QMetaObject::invokeMethod(m_client->m_backend, "enableMonitoring", Qt::QueuedConnection, Q_ARG(uintptr_t, reinterpret_cast<uintptr_t>(this)), @@ -66,6 +72,9 @@ bool QUACppNode::enableMonitoring(QOpcUa::NodeAttributes attr, const QOpcUaMonit bool QUACppNode::disableMonitoring(QOpcUa::NodeAttributes attr) { + if (!m_client) + return false; + return QMetaObject::invokeMethod(m_client->m_backend, "disableMonitoring", Qt::QueuedConnection, Q_ARG(uintptr_t, reinterpret_cast<uintptr_t>(this)), @@ -74,6 +83,9 @@ bool QUACppNode::disableMonitoring(QOpcUa::NodeAttributes attr) bool QUACppNode::modifyMonitoring(QOpcUa::NodeAttribute attr, QOpcUaMonitoringParameters::Parameter item, const QVariant &value) { + if (!m_client) + return false; + return QMetaObject::invokeMethod(m_client->m_backend, "modifyMonitoring", Qt::QueuedConnection, Q_ARG(uintptr_t, reinterpret_cast<uintptr_t>(this)), @@ -84,6 +96,9 @@ bool QUACppNode::modifyMonitoring(QOpcUa::NodeAttribute attr, QOpcUaMonitoringPa bool QUACppNode::browseChildren(QOpcUa::ReferenceTypeId referenceType, QOpcUa::NodeClasses nodeClassMask) { + if (!m_client) + return false; + return QMetaObject::invokeMethod(m_client->m_backend, "browseChildren", Qt::QueuedConnection, Q_ARG(uintptr_t, reinterpret_cast<uintptr_t>(this)), @@ -100,6 +115,9 @@ QString QUACppNode::nodeId() const bool QUACppNode::writeAttribute(QOpcUa::NodeAttribute attribute, const QVariant &value, QOpcUa::Types type, const QString &indexRange) { + if (!m_client) + return false; + return QMetaObject::invokeMethod(m_client->m_backend, "writeAttribute", Qt::QueuedConnection, Q_ARG(uintptr_t, reinterpret_cast<uintptr_t>(this)), @@ -112,6 +130,9 @@ bool QUACppNode::writeAttribute(QOpcUa::NodeAttribute attribute, const QVariant bool QUACppNode::writeAttributes(const QOpcUaNode::AttributeMap &toWrite, QOpcUa::Types valueAttributeType) { + if (!m_client) + return false; + return QMetaObject::invokeMethod(m_client->m_backend, "writeAttributes", Qt::QueuedConnection, Q_ARG(uintptr_t, reinterpret_cast<uintptr_t>(this)), @@ -123,6 +144,9 @@ bool QUACppNode::writeAttributes(const QOpcUaNode::AttributeMap &toWrite, QOpcUa bool QUACppNode::callMethod(const QString &methodNodeId, const QVector<QOpcUa::TypedVariant> &args) { + if (!m_client) + return false; + const UaNodeId methodId = UACppUtils::nodeIdFromQString(methodNodeId); return QMetaObject::invokeMethod(m_client->m_backend, "callMethod", |