summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Antonuk <alan.antonuk@gmail.com>2014-07-10 21:22:52 -0700
committerAlan Antonuk <alan.antonuk@gmail.com>2014-07-11 07:20:48 -0700
commit8ce585dd7d52952b0dc55a7e6db39f636d3075d6 (patch)
treec30b269a5152cb88d7de98cddc7e424c7917915e
parentcb1b44e2348ef26a24bbcb6a2c00ba94e372c189 (diff)
downloadrabbitmq-c-github-ask-8ce585dd7d52952b0dc55a7e6db39f636d3075d6.tar.gz
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
-rw-r--r--librabbitmq/amqp_consumer.c13
1 files 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;