Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-18498

QSslSocket: calling peek() on the socket causes the entire socket buffer to be copied to a new buffer, meaning that peek *does* have side-effects in certain use cases

    XMLWordPrintable

Details

    • 83c637aa942882880a73c7c4972c6c53332e0464

    Description

      Given the following use case:

      Two types of client connection can be made. Encrypted or unencrypted, with the requirement that a single socket is used and that the type of client connection can be detected upon initial connection.

      One way of doing this connection-type detection is by examining the first byte of the incoming packet after the client has connected. QIODevice::peek() purports to support this requirement, however in the given use case, causes the entire incoming data buffer of the socket to be copied to a new location. When the rest of the data must be read, there is no more data available since the socket buffer was emptied by calling peek().

      The attached test case reproduces the problem. To test it, build Qt with SSL support and run the example client html app (WebSocket.html) in either google chrome or firefox.

      Copy server.crt and server.key into a location that's accessible to the built application. It might be necessary to modify the two lines in _startServerEncryption:

      static const QString privateKeyFile = fileInAppPath ("server.key");
      static const QString localCertificateFile = fileInAppPath ("server.crt");

      To see the expected behaviour (where there has been no peeking of the incoming data stream), comment out line 96 which looks like this:

      qDebug() << "onReadyReadFirstBytes" << m_socketDecriptor << peek(1).toHex();
      

      Attachments

        Issue Links

          Activity

            People

              shkearns Shane Kearns
              cattell Matthew Cattell (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: