Skip to content

Commit

Permalink
Fixed bug that segfault while abnormal map is given
Browse files Browse the repository at this point in the history
  • Loading branch information
laruence committed Mar 5, 2013
1 parent 6937a42 commit 5695d31
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion routes/yaf_route_regex.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ static zval * yaf_route_regex_match(yaf_route_t *route, char *uir, int len TSRML
}

if (zend_hash_get_current_key_ex(ht, &key, &len, &idx, 0, NULL) == HASH_KEY_IS_LONG) {
if (map && zend_hash_index_find(Z_ARRVAL_P(map), idx, (void **)&name) == SUCCESS) {
if (map && zend_hash_index_find(Z_ARRVAL_P(map), idx, (void **)&name) == SUCCESS && Z_TYPE_PP(name) == IS_STRING) {
Z_ADDREF_P(*ppzval);
zend_hash_update(Z_ARRVAL_P(ret), Z_STRVAL_PP(name), Z_STRLEN_PP(name) + 1, (void **)ppzval, sizeof(zval *), NULL);
}
Expand Down
34 changes: 34 additions & 0 deletions tests/066.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
--TEST--
Check for Yaf_Route_Regex with abnormal map
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--FILE--
<?php
$request = new Yaf_Request_Http("/subdir/ap/1.2/xxx/name/value", "/subdir");

$router = new Yaf_Router();

$router->addRoute("ap", new Yaf_Route_Regex(
"#^/ap/([^/]*)/([^/]*)/*#i",
array(
"action" => 'ap',
),
array(
1 => 23432,
2 => NULL,
)
))->route($request);

var_dump($router->getCurrentRoute());
var_dump($request->getParam(1));
var_dump($request->getActionName());
var_dump($request->getControllerName());
var_dump($request->getParam('name'));

?>
--EXPECTF--
string(2) "ap"
NULL
string(2) "ap"
NULL
NULL

0 comments on commit 5695d31

Please sign in to comment.