Skip to content

Commit

Permalink
Merge pull request #744 from sjinks/issue-744
Browse files Browse the repository at this point in the history
[BUG] [CRASH] Segmentation Fault in Phalcon\Tag::setDI() and setDefaults()
  • Loading branch information
Phalcon committed Jun 29, 2013
2 parents a36c3f8 + 1d002dd commit 5116359
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 6 deletions.
16 changes: 10 additions & 6 deletions ext/tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,17 @@ PHALCON_INIT_CLASS(Phalcon_Tag){
PHP_METHOD(Phalcon_Tag, setDI){

zval *dependency_injector;

PHALCON_MM_GROW();

phalcon_fetch_params(0, 1, 0, &dependency_injector);
phalcon_fetch_params(1, 1, 0, &dependency_injector);

if (Z_TYPE_P(dependency_injector) != IS_OBJECT) {
PHALCON_THROW_EXCEPTION_STR(phalcon_tag_exception_ce, "Parameter dependencyInjector must be an Object");
if (Z_TYPE_P(dependency_injector) != IS_OBJECT || !instanceof_function_ex(Z_OBJCE_P(dependency_injector), phalcon_diinterface_ce, 1 TSRMLS_CC)) {
PHALCON_THROW_EXCEPTION_STR(phalcon_tag_exception_ce, "Parameter dependencyInjector must implement Phalcon\\DiInterface interface");
return;
}
phalcon_update_static_property(SL("phalcon\\tag"), SL("_dependencyInjector"), dependency_injector TSRMLS_CC);

PHALCON_MM_RESTORE();
}

/**
Expand Down Expand Up @@ -266,14 +268,16 @@ PHP_METHOD(Phalcon_Tag, setDefaults){

zval *values;

phalcon_fetch_params(0, 1, 0, &values);
PHALCON_MM_GROW();

phalcon_fetch_params(1, 1, 0, &values);

if (Z_TYPE_P(values) != IS_ARRAY) {
PHALCON_THROW_EXCEPTION_STR(phalcon_tag_exception_ce, "An array is required as default values");
return;
}
phalcon_update_static_property(SL("phalcon\\tag"), SL("_displayValues"), values TSRMLS_CC);

PHALCON_MM_RESTORE();
}

/**
Expand Down
74 changes: 74 additions & 0 deletions unit-tests/TagTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

/*
+------------------------------------------------------------------------+
| Phalcon Framework |
+------------------------------------------------------------------------+
| Copyright (c) 2011-2012 Phalcon Team (http://www.phalconphp.com) |
+------------------------------------------------------------------------+
| This source file is subject to the New BSD License that is bundled |
| with this package in the file docs/LICENSE.txt. |
| |
| If you did not receive a copy of the license and are unable to |
| obtain it through the world-wide-web, please send an email |
| to [email protected] so we can send you a copy immediately. |
+------------------------------------------------------------------------+
| Authors: Andres Gutierrez <[email protected]> |
| Eduar Carvajal <[email protected]> |
+------------------------------------------------------------------------+
*/

class DIDescendant extends Phalcon\DI {}

class TagTest extends PHPUnit_Framework_TestCase
{

public function setUp()
{
}

public function testIssue744()
{
$v = new Phalcon\Tag;

try {
$v->setDI(0);
$this->assertTrue(false);
}
catch (Exception $e) {
$this->assertTrue(true);
}

try {
$v->setDI(new stdClass());
$this->assertTrue(false);
}
catch (Exception $e) {
$this->assertTrue(true);
}

try {
$v->setDI(new Phalcon\DI());
$this->assertTrue(true);
}
catch (Exception $e) {
$this->assertTrue(false);
}

try {
$v->setDI(new DIDescendant());
$this->assertTrue(true);
}
catch (Exception $e) {
$this->assertTrue(false);
}

try {
$v->setDefaults(0);
$this->assertTrue(false);
}
catch (Exception $e) {
$this->assertTrue(true);
}
}
}

0 comments on commit 5116359

Please sign in to comment.