Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Use of read_some in bitcoinrpc.cpp #824

Open
xanatos opened this Issue · 1 comment

2 participants

@xanatos

In bitcoinrpc.cpp, class SSLIOStreamDevice, to read from the socket (or socket+ssl) stream the function read_some is used.

std::streamsize read(char* s, std::streamsize n)
{
    handshake(ssl::stream_base::server); // HTTPS servers read first
    if (fUseSSL) return stream.read_some(asio::buffer(s, n));
    return stream.next_layer().read_some(asio::buffer(s, n));
}

The problem is that read_some doesn't guarantee to read n bytes. From http://www.boost.org/doc/libs/1_38_0/doc/html/boost_asio/reference/basic_stream_socket/read_some/overload1.html

Remarks

The read_some operation may not read all of the requested number of bytes. Consider using the read function if you need to ensure that the requested amount of data is read before the blocking operation completes.

Now, SSLIOStreamDevice is a bidirectional device. It implements a read and a write. Reading from here http://www.boost.org/doc/libs/1_48_0/libs/iostreams/doc/concepts/bidirectional_device.html what the read should do we get:

std::streamsize read(char* s, std::streamsize n) 
    {
        // Reads up to n characters from the input 
        // sequence into the buffer s, returning the number 
        // of characters read. **Returning a value less than n 
        // indicates end-of-sequence.**
    }
@laanwj
Owner

So in principle we should be calling read (which has the "return all or error" semantic), not read_some.

I wonder if it's possible to come up with a test that causes this to fail.

@laanwj laanwj added the RPC label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.