From 0b841bdfdcef9f3c0f00aa79bd8142ace44dd739 Mon Sep 17 00:00:00 2001 From: Bogdan Padalko Date: Tue, 22 Dec 2015 22:07:20 +0200 Subject: [PATCH] Fix segfault when channel zval type != IS_OBJECT --- php_amqp.h | 3 +- ...change_declare_with_stalled_reference.phpt | 40 +++++++++++++++++++ ...pqueue_declare_with_stalled_reference.phpt | 40 +++++++++++++++++++ 3 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 tests/amqpexchange_declare_with_stalled_reference.phpt create mode 100644 tests/amqpqueue_declare_with_stalled_reference.phpt diff --git a/php_amqp.h b/php_amqp.h index abb01205..35efcdba 100644 --- a/php_amqp.h +++ b/php_amqp.h @@ -233,8 +233,7 @@ struct _amqp_connection_object { #endif -#define PHP_AMQP_GET_CHANNEL_RESOURCE(obj) (PHP_AMQP_GET_CHANNEL(obj))->channel_resource - +#define PHP_AMQP_GET_CHANNEL_RESOURCE(obj) (IS_OBJECT == Z_TYPE_P(obj) ? (PHP_AMQP_GET_CHANNEL(obj))->channel_resource : NULL) #define PHP_AMQP_VERIFY_CONNECTION_ERROR(error, reason) \ char verify_connection_error_tmp[255]; \ diff --git a/tests/amqpexchange_declare_with_stalled_reference.phpt b/tests/amqpexchange_declare_with_stalled_reference.phpt new file mode 100644 index 00000000..1215326c --- /dev/null +++ b/tests/amqpexchange_declare_with_stalled_reference.phpt @@ -0,0 +1,40 @@ +--TEST-- +AMQPExchange - declare with stalled reference +--SKIPIF-- + +--FILE-- +declareExchange(); +} catch (\Exception $e) { + echo get_class($e), ': ', $e->getMessage(), PHP_EOL; +} + +?> +--EXPECT-- +AMQPChannelException: Could not declare exchange. Stale reference to the channel object. diff --git a/tests/amqpqueue_declare_with_stalled_reference.phpt b/tests/amqpqueue_declare_with_stalled_reference.phpt new file mode 100644 index 00000000..9a21c3b6 --- /dev/null +++ b/tests/amqpqueue_declare_with_stalled_reference.phpt @@ -0,0 +1,40 @@ +--TEST-- +AMQPQueue - declare with stalled reference +--SKIPIF-- + +--FILE-- +declareQueue(); +} catch (\Exception $e) { + echo get_class($e), ': ', $e->getMessage(), PHP_EOL; +} + +?> +--EXPECT-- +AMQPChannelException: Could not declare queue. Stale reference to the channel object.