From 357bdb369206eb91fe643b7c275ce15248b4f5f8 Mon Sep 17 00:00:00 2001 From: Mike Stitt Date: Sat, 28 Jun 2014 09:12:46 -0400 Subject: Allow INITIAL bufffer and page size configuration Signed-off-by: Mike Stitt --- librabbitmq/amqp_connection.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'librabbitmq/amqp_connection.c') diff --git a/librabbitmq/amqp_connection.c b/librabbitmq/amqp_connection.c index 5d70b07..ccaa73d 100644 --- a/librabbitmq/amqp_connection.c +++ b/librabbitmq/amqp_connection.c @@ -48,9 +48,18 @@ #include #include -#define INITIAL_FRAME_POOL_PAGE_SIZE 65536 -#define INITIAL_DECODING_POOL_PAGE_SIZE 131072 -#define INITIAL_INBOUND_SOCK_BUFFER_SIZE 131072 +#ifndef AMQP_INITIAL_FRAME_POOL_PAGE_SIZE +#define AMQP_INITIAL_FRAME_POOL_PAGE_SIZE 65536 +#endif + +#ifndef AMQP_INITIAL_DECODING_POOL_PAGE_SIZE +#define AMQP_INITIAL_DECODING_POOL_PAGE_SIZE 131072 +#endif + +#ifndef AMQP_INITIAL_INBOUND_SOCK_BUFFER_SIZE +#define AMQP_INITIAL_INBOUND_SOCK_BUFFER_SIZE 131072 +#endif + #define ENFORCE_STATE(statevec, statenum) \ { \ @@ -72,7 +81,7 @@ amqp_connection_state_t amqp_new_connection(void) return NULL; } - res = amqp_tune_connection(state, 0, INITIAL_FRAME_POOL_PAGE_SIZE, 0); + res = amqp_tune_connection(state, 0, AMQP_INITIAL_FRAME_POOL_PAGE_SIZE, 0); if (0 != res) { goto out_nomem; } @@ -85,8 +94,8 @@ amqp_connection_state_t amqp_new_connection(void) is also the minimum frame size */ state->target_size = 8; - state->sock_inbound_buffer.len = INITIAL_INBOUND_SOCK_BUFFER_SIZE; - state->sock_inbound_buffer.bytes = malloc(INITIAL_INBOUND_SOCK_BUFFER_SIZE); + state->sock_inbound_buffer.len = AMQP_INITIAL_INBOUND_SOCK_BUFFER_SIZE; + state->sock_inbound_buffer.bytes = malloc(AMQP_INITIAL_INBOUND_SOCK_BUFFER_SIZE); if (state->sock_inbound_buffer.bytes == NULL) { goto out_nomem; } -- cgit v1.2.1 From 38c8cdcd64b0a260382c5f2fc73e5abe1fc766fc Mon Sep 17 00:00:00 2001 From: Alan Antonuk Date: Fri, 11 Jul 2014 07:55:40 -0700 Subject: Remove unused INITIAL_DECODING_POOL_PAGE_SIZE def AMQP_INITIAL_DECODING_POOL_PAGE_SIZE isn't used anywhere in the code. Getting rid of it. --- librabbitmq/amqp_connection.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'librabbitmq/amqp_connection.c') diff --git a/librabbitmq/amqp_connection.c b/librabbitmq/amqp_connection.c index ccaa73d..078ffb6 100644 --- a/librabbitmq/amqp_connection.c +++ b/librabbitmq/amqp_connection.c @@ -52,10 +52,6 @@ #define AMQP_INITIAL_FRAME_POOL_PAGE_SIZE 65536 #endif -#ifndef AMQP_INITIAL_DECODING_POOL_PAGE_SIZE -#define AMQP_INITIAL_DECODING_POOL_PAGE_SIZE 131072 -#endif - #ifndef AMQP_INITIAL_INBOUND_SOCK_BUFFER_SIZE #define AMQP_INITIAL_INBOUND_SOCK_BUFFER_SIZE 131072 #endif -- cgit v1.2.1 From 8956003e3d1fd97cf52969a2c4f988cbcb81100d Mon Sep 17 00:00:00 2001 From: Alan Antonuk Date: Mon, 14 Jul 2014 22:30:27 -0700 Subject: FIX: Improve invalid frame detection code. Improve detection of invalid AMQP frame header before allocating frame buffer. This fixes #187. Thanks to Mike Stitt for the inspiration on this. --- librabbitmq/amqp_connection.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'librabbitmq/amqp_connection.c') diff --git a/librabbitmq/amqp_connection.c b/librabbitmq/amqp_connection.c index 078ffb6..cb82e46 100644 --- a/librabbitmq/amqp_connection.c +++ b/librabbitmq/amqp_connection.c @@ -279,14 +279,22 @@ int amqp_handle_input(amqp_connection_state_t state, /* frame length is 3 bytes in */ channel = amqp_d16(raw_frame, 1); - channel_pool = amqp_get_or_create_channel_pool(state, channel); - if (NULL == channel_pool) { - return AMQP_STATUS_NO_MEMORY; + if ((int)channel > state->channel_max) { + return AMQP_STATUS_BAD_AMQP_DATA; } state->target_size = amqp_d32(raw_frame, 3) + HEADER_SIZE + FOOTER_SIZE; + if ((size_t)state->frame_max < state->target_size) { + return AMQP_STATUS_BAD_AMQP_DATA; + } + + channel_pool = amqp_get_or_create_channel_pool(state, channel); + if (NULL == channel_pool) { + return AMQP_STATUS_NO_MEMORY; + } + amqp_pool_alloc_bytes(channel_pool, state->target_size, &state->inbound_buffer); if (NULL == state->inbound_buffer.bytes) { return AMQP_STATUS_NO_MEMORY; -- cgit v1.2.1 From 45302cf00f6e585cba5ff1df6759de2c50e3d968 Mon Sep 17 00:00:00 2001 From: Alan Antonuk Date: Sat, 2 Aug 2014 21:52:09 -0700 Subject: FIX: don't range-check channel_ids. Even if a channel_max is specified, channel_ids can be any number, so don't range-check channel_ids received. At present this gets rabbitmq-c back into compliance with the way the RabbitMQ broker works. See issue #187, #195 To correctly enforce channel_max from the client side, rabbitmq-c would need to track open channels, which is a bit more involved to do correctly. --- librabbitmq/amqp_connection.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'librabbitmq/amqp_connection.c') diff --git a/librabbitmq/amqp_connection.c b/librabbitmq/amqp_connection.c index cb82e46..88136cd 100644 --- a/librabbitmq/amqp_connection.c +++ b/librabbitmq/amqp_connection.c @@ -279,10 +279,6 @@ int amqp_handle_input(amqp_connection_state_t state, /* frame length is 3 bytes in */ channel = amqp_d16(raw_frame, 1); - if ((int)channel > state->channel_max) { - return AMQP_STATUS_BAD_AMQP_DATA; - } - state->target_size = amqp_d32(raw_frame, 3) + HEADER_SIZE + FOOTER_SIZE; -- cgit v1.2.1 From bfd8cc9129da46136691a88c06d505b78f0043ae Mon Sep 17 00:00:00 2001 From: Alan Antonuk Date: Tue, 26 Aug 2014 21:31:42 -0700 Subject: Update copyright on files changed in 2014. --- librabbitmq/amqp_connection.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'librabbitmq/amqp_connection.c') diff --git a/librabbitmq/amqp_connection.c b/librabbitmq/amqp_connection.c index 88136cd..3315969 100644 --- a/librabbitmq/amqp_connection.c +++ b/librabbitmq/amqp_connection.c @@ -3,7 +3,7 @@ * ***** BEGIN LICENSE BLOCK ***** * Version: MIT * - * Portions created by Alan Antonuk are Copyright (c) 2012-2013 + * Portions created by Alan Antonuk are Copyright (c) 2012-2014 * Alan Antonuk. All Rights Reserved. * * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. -- cgit v1.2.1