phalcon/cphalcon — pull request #770 by sjinks (2013-07-02 21:53:10+00:00)
Title: Fix Segmentation Faults in Volt Compiler

These are unlikely to happen unless someone wants to crash Phalcon.

First one:
```php
$c = new \Phalcon\Mvc\View\Engine\Volt\Compiler(new \Phalcon\Mvc\View());
$c->compileIf(array(), false);
```

In this case:
```c
zval *expr_code; /* not initialized */

if (phalcon_array_isset_string(statement, SS("expr"))) {
PHALCON_OBS_VAR(expr);
phalcon_array_fetch_string(&expr, statement, SL("expr"), PH_NOISY_CC);

PHALCON_INIT_VAR(expr_code);
phalcon_call_method_p1(expr_code, this_ptr, "expression", expr);
}
/* if we take 'else' branch (!isset($statement['expr'])), $expr_code will be left uninitialized resulting in a crash */
PHALCON_SCONCAT_SVS(compilation, "");
```

Second one (this one is harder to reproduce but still possible):
```php
$c = new \Phalcon\Mvc\View\Engine\Volt\Compiler(new \Phalcon\Mvc\View());
$c->compileMacro(array('name' => 'test', 'parameters' => array()), false);
```

In this case:
```c
zval *block_code; /* not initialized */

if (phalcon_array_isset_string(statement, SS("block_statements"))) {
/* ... */
PHALCON_INIT_VAR(block_code);
phalcon_call_method_p2(block_code, this_ptr, "_statementlist", block_statements, extends_mode);
}
/* Take 'false' branch (!isset($statement['block_statements'])), $block_code will be left uninitialized resulting in a crash */
PHALCON_SCONCAT_VS(code, block_code, "");
```

I do understand that these scenarios are highly unlikely IRL (the parser won't allow this, one need to invoke compileXXX statements manually), but it is better not to leave any chance to crashes :-)