Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] [CRASH] Segmentation Fault in Phalcon\Tag::setDI() and setDefaults() #744

Merged
merged 2 commits into from Jun 29, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}