Skip to content

Commit

Permalink
Merge pull request #743 from sjinks/issue-743
Browse files Browse the repository at this point in the history
[BUG] [CRASH] Segmentation Fault in Phalcon\Validation::bind()
  • Loading branch information
Phalcon committed Jun 29, 2013
2 parents 1e3e20d + 44387a3 commit a36c3f8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
15 changes: 8 additions & 7 deletions ext/validation.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ PHP_METHOD(Phalcon_Validation, getMessages){
/**
* Appends a message to the messages list
*
* @param Phalcon\Validation\MessageInterface $message
* @param Phalcon\Validation\Message $message
* @return Phalcon\Validation
*/
PHP_METHOD(Phalcon_Validation, appendMessage){
Expand Down Expand Up @@ -367,22 +367,23 @@ PHP_METHOD(Phalcon_Validation, bind){

zval *entity, *data;

phalcon_fetch_params(0, 2, 0, &entity, &data);
PHALCON_MM_GROW();

phalcon_fetch_params(1, 2, 0, &entity, &data);

if (Z_TYPE_P(entity) != IS_OBJECT) {
PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "The entity must be an object");
return;
}
if (Z_TYPE_P(data) != IS_ARRAY) {
if (Z_TYPE_P(data) != IS_OBJECT) {
PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "The data to validate must be an array or object");
return;
}
if (Z_TYPE_P(data) != IS_ARRAY && Z_TYPE_P(data) != IS_OBJECT) {
PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "The data to validate must be an array or object");
return;
}

phalcon_update_property_this(this_ptr, SL("_entity"), entity TSRMLS_CC);
phalcon_update_property_this(this_ptr, SL("_data"), data TSRMLS_CC);

PHALCON_MM_RESTORE();
RETURN_THISW();
}

Expand Down
12 changes: 12 additions & 0 deletions unit-tests/ValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -838,4 +838,16 @@ public function testValidationFiltering()
$_POST = array();
}


public function testIssue743()
{
$v = new Phalcon\Validation;
try {
$v->bind(0, 0);
}
catch (Exception $e) {
$this->assertTrue(true);
}
}

}

0 comments on commit a36c3f8

Please sign in to comment.