Skip to content

Commit

Permalink
Fix segfault when channel zval type != IS_OBJECT
Browse files Browse the repository at this point in the history
  • Loading branch information
pinepain committed Jan 20, 2016
1 parent e626832 commit 0b841bd
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 2 deletions.
3 changes: 1 addition & 2 deletions php_amqp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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]; \
Expand Down
40 changes: 40 additions & 0 deletions tests/amqpexchange_declare_with_stalled_reference.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
--TEST--
AMQPExchange - declare with stalled reference
--SKIPIF--
<?php if (!extension_loaded("amqp")) print "skip"; ?>
--FILE--
<?php
class ConnectionMock extends AMQPConnection {
public function __construct(array $credentials = array())
{
}
}

class ChannelMock extends AMQPChannel {
public function __construct(AMQPConnection $amqp_connection)
{
}
}

class ExchangeMock extends \AMQPExchange
{
public function __construct(AMQPChannel $amqp_channel)
{
}
}

$cnn = new ConnectionMock();
$ch = new ChannelMock($cnn);

$e = new ExchangeMock($ch);


try {
$e->declareExchange();
} catch (\Exception $e) {
echo get_class($e), ': ', $e->getMessage(), PHP_EOL;
}

?>
--EXPECT--
AMQPChannelException: Could not declare exchange. Stale reference to the channel object.
40 changes: 40 additions & 0 deletions tests/amqpqueue_declare_with_stalled_reference.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
--TEST--
AMQPQueue - declare with stalled reference
--SKIPIF--
<?php if (!extension_loaded("amqp")) print "skip"; ?>
--FILE--
<?php
class ConnectionMock extends AMQPConnection {
public function __construct(array $credentials = array())
{
}
}

class ChannelMock extends AMQPChannel {
public function __construct(AMQPConnection $amqp_connection)
{
}
}

class QueueMock extends \AMQPQueue
{
public function __construct(AMQPChannel $amqp_channel)
{
}
}

$cnn = new ConnectionMock();
$ch = new ChannelMock($cnn);

$e = new QueueMock($ch);


try {
$e->declareQueue();
} catch (\Exception $e) {
echo get_class($e), ': ', $e->getMessage(), PHP_EOL;
}

?>
--EXPECT--
AMQPChannelException: Could not declare queue. Stale reference to the channel object.

0 comments on commit 0b841bd

Please sign in to comment.