Merge branch 'take-request-response-size-into-malloc' into 'develop'

Update proxy malloc to add the struct size onto the request/response buffer

See merge request open-source/flexnbd-c!45
This commit is contained in:
Chris Elsworth
2018-02-14 05:28:24 +00:00
3 changed files with 27 additions and 5 deletions

2
debian/changelog vendored
View File

@@ -16,6 +16,8 @@ flexnbd (0.2.0) UNRELEASED; urgency=medium
disconnecting and retrying (#36, !40)
* Ignore ends of discs that stray outside of 512-byte sector sizes (!42).
* Tweak logging for readloop failures (!44)
* Alter semantics of NBD_MAX_BLOCK_SIZE to remove struct size overheads when
calculating if a request exceeds the max block size (!45)
-- James Carter <james.carter@bytemark.co.uk> Thu, 11 Jan 2018 10:05:35 +0000

View File

@@ -76,8 +76,12 @@ struct proxier* proxy_create(
}
out->init.buf = xmalloc( sizeof( struct nbd_init_raw ) );
out->req.buf = xmalloc( NBD_MAX_SIZE );
out->rsp.buf = xmalloc( NBD_MAX_SIZE );
/* Add on the request / reply size to our malloc to accommodate both
* the struct and the data
*/
out->req.buf = xmalloc( NBD_MAX_SIZE + NBD_REQUEST_SIZE );
out->rsp.buf = xmalloc( NBD_MAX_SIZE + NBD_REPLY_SIZE );
log_context = xmalloc( strlen(s_upstream_address) + strlen(s_upstream_port) + 2 );
sprintf(log_context, "%s:%s", s_upstream_address, s_upstream_port);
@@ -452,15 +456,18 @@ int proxy_read_from_downstream( struct proxier *proxy, int state )
return EXIT;
}
/* Simple validations */
/* Simple validations -- the request / reply size have already
* been taken into account in the xmalloc, so no need to worry
* about them here
*/
if ( request->type == REQUEST_READ ) {
if (request->len > ( NBD_MAX_SIZE - NBD_REPLY_SIZE ) ) {
if ( request->len > NBD_MAX_SIZE ) {
warn( "NBD read request size %"PRIu32" too large", request->len );
return EXIT;
}
}
if ( request->type == REQUEST_WRITE ) {
if (request->len > ( NBD_MAX_SIZE - NBD_REQUEST_SIZE ) ) {
if ( request->len > NBD_MAX_SIZE ) {
warn( "NBD write request size %"PRIu32" too large", request->len );
return EXIT;
}

View File

@@ -207,4 +207,17 @@ module ProxyTests
end
end
end
def test_maximum_write_request_size
# Defined in src/common/nbdtypes.h
nbd_max_block_size = 32 * 1024 * 1024
@env.writefile1('0' * 40 * 1024)
with_proxied_client do |client|
# This will crash with EPIPE if the proxy dies.
client.write(0, b * nbd_max_block_size)
rsp = client.read_response
assert_equal FlexNBD::REPLY_MAGIC, rsp[:magic]
assert_equal 0, rsp[:error]
end
end
end