Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Use of read_some in bitcoinrpc.cpp #824

xanatos opened this Issue · 1 comment

2 participants


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


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 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.**

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.