diff options
author | Tony Garnock-Jones <tonygarnockjones@gmail.com> | 2010-04-16 11:05:35 +1200 |
---|---|---|
committer | Tony Garnock-Jones <tonygarnockjones@gmail.com> | 2010-04-16 11:05:35 +1200 |
commit | c3a1d3b60e7bf4913e971b80226ce04780d91594 (patch) | |
tree | ee72c7e4c2c6171ec8058fba06641e43be7f3225 /librabbitmq/amqp_table.c | |
parent | c49ffc97f70148fdb7b201d23e39c06a05575b59 (diff) | |
download | rabbitmq-c-github-ask-c3a1d3b60e7bf4913e971b80226ce04780d91594.tar.gz |
Check results of amqp_pool_alloc() and friends.
Diffstat (limited to 'librabbitmq/amqp_table.c')
-rw-r--r-- | librabbitmq/amqp_table.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/librabbitmq/amqp_table.c b/librabbitmq/amqp_table.c index fda85cb..25c5932 100644 --- a/librabbitmq/amqp_table.c +++ b/librabbitmq/amqp_table.c @@ -114,8 +114,13 @@ static int amqp_decode_array(amqp_bytes_t encoded, output->num_entries = num_entries; output->entries = amqp_pool_alloc(pool, num_entries * sizeof(amqp_field_value_t)); - memcpy(output->entries, entries, num_entries * sizeof(amqp_field_value_t)); + if (output->entries == NULL && num_entries > 0) { + /* NULL is legitimate if we requested a zero-length block. */ + free(entries); + return -ENOMEM; + } + memcpy(output->entries, entries, num_entries * sizeof(amqp_field_value_t)); free(entries); *offsetptr = offset; @@ -174,8 +179,13 @@ int amqp_decode_table(amqp_bytes_t encoded, output->num_entries = num_entries; output->entries = amqp_pool_alloc(pool, num_entries * sizeof(amqp_table_entry_t)); - memcpy(output->entries, entries, num_entries * sizeof(amqp_table_entry_t)); + if (output->entries == NULL && num_entries > 0) { + /* NULL is legitimate if we requested a zero-length block. */ + free(entries); + return -ENOMEM; + } + memcpy(output->entries, entries, num_entries * sizeof(amqp_table_entry_t)); free(entries); *offsetptr = offset; |