From e9cb913a37318284353790f46edc648a630d758f Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Tue, 1 Aug 2017 15:44:13 +0200 Subject: winrt: Check for valid m_socketObject before accessing socket information If the socket was created without giving the socket type, ensureNativeSocket was not called and thus m_socketObject is 0. Calling localName and friends caused a crash because they accesses the object unconditionally. Change-Id: I442e3d1492458161fb8660f1b2f17d52b37a2935 Reviewed-by: Alex Blasche --- src/bluetooth/qbluetoothsocket_winrt.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/bluetooth/qbluetoothsocket_winrt.cpp b/src/bluetooth/qbluetoothsocket_winrt.cpp index 4a9d1b93..501ffd74 100644 --- a/src/bluetooth/qbluetoothsocket_winrt.cpp +++ b/src/bluetooth/qbluetoothsocket_winrt.cpp @@ -422,6 +422,9 @@ QString QBluetoothSocketPrivate::localName() const QBluetoothAddress QBluetoothSocketPrivate::localAddress() const { + if (!m_socketObject) + return QBluetoothAddress(); + HRESULT hr; ComPtr info; hr = m_socketObject->get_Information(&info); @@ -437,6 +440,9 @@ QBluetoothAddress QBluetoothSocketPrivate::localAddress() const quint16 QBluetoothSocketPrivate::localPort() const { + if (!m_socketObject) + return 0; + HRESULT hr; ComPtr info; hr = m_socketObject->get_Information(&info); @@ -449,6 +455,9 @@ quint16 QBluetoothSocketPrivate::localPort() const QString QBluetoothSocketPrivate::peerName() const { + if (!m_socketObject) + return QString(); + HRESULT hr; ComPtr info; hr = m_socketObject->get_Information(&info); @@ -464,6 +473,9 @@ QString QBluetoothSocketPrivate::peerName() const QBluetoothAddress QBluetoothSocketPrivate::peerAddress() const { + if (!m_socketObject) + return QBluetoothAddress(); + HRESULT hr; ComPtr info; hr = m_socketObject->get_Information(&info); @@ -479,6 +491,9 @@ QBluetoothAddress QBluetoothSocketPrivate::peerAddress() const quint16 QBluetoothSocketPrivate::peerPort() const { + if (!m_socketObject) + return 0; + HRESULT hr; ComPtr info; hr = m_socketObject->get_Information(&info); -- cgit v1.2.3