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

This alters the meaning of NBD_MAX_SIZE to be the actual max request size
we'll accept over nbd.  Previously it was *nearly* the max size we'd
accept depending on the size of the struct.
This commit is contained in:
Patrick J Cherry
2018-02-12 19:04:29 +00:00
parent c4bab3f81f
commit 1c66b56af1

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 / response 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_RESPONSE_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;
}