From 8ce585dd7d52952b0dc55a7e6db39f636d3075d6 Mon Sep 17 00:00:00 2001 From: Alan Antonuk Date: Thu, 10 Jul 2014 21:22:52 -0700 Subject: FIX: incorrect OOM for 0-len xchg in amqp_consume. This fixes a bug in amqp_consume where the function would incorrectly return an OOM condition when a 0-length exchange name was returned. Fixes #192 --- librabbitmq/amqp_consumer.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/librabbitmq/amqp_consumer.c b/librabbitmq/amqp_consumer.c index 6c6c1c9..be71118 100644 --- a/librabbitmq/amqp_consumer.c +++ b/librabbitmq/amqp_consumer.c @@ -131,6 +131,13 @@ void amqp_destroy_envelope(amqp_envelope_t *envelope) amqp_bytes_free(envelope->consumer_tag); } +static +int amqp_bytes_malloc_dup_failed(amqp_bytes_t bytes) { + if (bytes.len != 0 && bytes.bytes == NULL) { + return 1; + } + return 0; +} amqp_rpc_reply_t amqp_consume_message(amqp_connection_state_t state, amqp_envelope_t *envelope, @@ -168,9 +175,9 @@ amqp_consume_message(amqp_connection_state_t state, amqp_envelope_t *envelope, envelope->exchange = amqp_bytes_malloc_dup(delivery_method->exchange); envelope->routing_key = amqp_bytes_malloc_dup(delivery_method->routing_key); - if (NULL == envelope->consumer_tag.bytes || - NULL == envelope->exchange.bytes || - NULL == envelope->routing_key.bytes) { + if (amqp_bytes_malloc_dup_failed(envelope->consumer_tag) || + amqp_bytes_malloc_dup_failed(envelope->exchange) || + amqp_bytes_malloc_dup_failed(envelope->routing_key)) { ret.reply_type = AMQP_RESPONSE_LIBRARY_EXCEPTION; ret.library_error = AMQP_STATUS_NO_MEMORY; goto error_out2; -- cgit v1.2.1