diff options
author | Shane Kearns <shane.kearns@accenture.com> | 2011-05-05 15:32:11 (GMT) |
---|---|---|
committer | Shane Kearns <shane.kearns@accenture.com> | 2011-05-05 15:41:35 (GMT) |
commit | 19edac88af53eea7f733cabbaee77f9b725b7ea9 (patch) | |
tree | 6f853fd7568c82af37ae3e642d5b9b4e8295b45b | |
parent | 57e191e9cb69cd132612122b30c94ee013ef4a50 (diff) | |
download | Qt-19edac88af53eea7f733cabbaee77f9b725b7ea9.zip Qt-19edac88af53eea7f733cabbaee77f9b725b7ea9.tar.gz Qt-19edac88af53eea7f733cabbaee77f9b725b7ea9.tar.bz2 |
Sockets: Fix potential null pointer usages
QAbstractSocketEngine::createSocketEngine can return 0 as well as throw.
In two cases the pointer was being used before the null check, in a 3rd
case the null check was missing.
Reviewed-by: Markus Goetz
-rw-r--r-- | src/network/socket/qabstractsocket.cpp | 16 | ||||
-rw-r--r-- | src/network/socket/qtcpserver.cpp | 5 |
2 files changed, 13 insertions, 8 deletions
diff --git a/src/network/socket/qabstractsocket.cpp b/src/network/socket/qabstractsocket.cpp index 090f092..22729a8 100644 --- a/src/network/socket/qabstractsocket.cpp +++ b/src/network/socket/qabstractsocket.cpp @@ -547,15 +547,15 @@ bool QAbstractSocketPrivate::initSocketLayer(QAbstractSocket::NetworkLayerProtoc resetSocketLayer(); socketEngine = QAbstractSocketEngine::createSocketEngine(q->socketType(), proxyInUse, q); -#ifndef QT_NO_BEARERMANAGEMENT - //copy network session down to the socket engine (if it has been set) - socketEngine->setProperty("_q_networksession", q->property("_q_networksession")); -#endif if (!socketEngine) { socketError = QAbstractSocket::UnsupportedSocketOperationError; q->setErrorString(QAbstractSocket::tr("Operation on socket is not supported")); return false; } +#ifndef QT_NO_BEARERMANAGEMENT + //copy network session down to the socket engine (if it has been set) + socketEngine->setProperty("_q_networksession", q->property("_q_networksession")); +#endif #ifndef QT_NO_NETWORKPROXY //copy user agent to socket engine (if it has been set) socketEngine->setProperty("_q_user-agent", q->property("_q_user-agent")); @@ -1609,15 +1609,15 @@ bool QAbstractSocket::setSocketDescriptor(int socketDescriptor, SocketState sock d->resetSocketLayer(); d->socketEngine = QAbstractSocketEngine::createSocketEngine(socketDescriptor, this); -#ifndef QT_NO_BEARERMANAGEMENT - //copy network session down to the socket engine (if it has been set) - d->socketEngine->setProperty("_q_networksession", property("_q_networksession")); -#endif if (!d->socketEngine) { d->socketError = UnsupportedSocketOperationError; setErrorString(tr("Operation on socket is not supported")); return false; } +#ifndef QT_NO_BEARERMANAGEMENT + //copy network session down to the socket engine (if it has been set) + d->socketEngine->setProperty("_q_networksession", property("_q_networksession")); +#endif bool result = d->socketEngine->initialize(socketDescriptor, socketState); if (!result) { d->socketError = d->socketEngine->error(); diff --git a/src/network/socket/qtcpserver.cpp b/src/network/socket/qtcpserver.cpp index 5a60764..026ceb4 100644 --- a/src/network/socket/qtcpserver.cpp +++ b/src/network/socket/qtcpserver.cpp @@ -416,6 +416,11 @@ bool QTcpServer::setSocketDescriptor(int socketDescriptor) if (d->socketEngine) delete d->socketEngine; d->socketEngine = QAbstractSocketEngine::createSocketEngine(socketDescriptor, this); + if (!d->socketEngine) { + d->serverSocketError = QAbstractSocket::UnsupportedSocketOperationError; + d->serverSocketErrorString = tr("Operation on socket is not supported"); + return false; + } #ifndef QT_NO_BEARERMANAGEMENT //copy network session down to the socket engine (if it has been set) d->socketEngine->setProperty("_q_networksession", property("_q_networksession")); |