Skip to content
Browse files

Fixed segfaults while using uninitialized objects

  • Loading branch information...
1 parent 1253d86 commit c1e901a2e5b91088347f8ad15d1928460012e61f @laruence committed
Showing with 44 additions and 35 deletions.
  1. +2 −1 requests/http.c
  2. +3 −1 requests/simple.c
  3. +2 −1 routes/map.c
  4. +6 −14 routes/regex.c
  5. +5 −7 routes/rewrite.c
  6. +3 −1 routes/simple.c
  7. +4 −2 routes/supervar.c
  8. +4 −4 tests/051.phpt
  9. +2 −1 views/simple.c
  10. +6 −2 yaf_application.c
  11. +7 −1 yaf_exception.h
View
3 requests/http.c
@@ -14,7 +14,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: http.c 325431 2012-04-24 07:41:42Z laruence $ */
+/* $Id: http.c 327549 2012-09-09 03:02:48Z laruence $ */
#include "ext/standard/url.h"
@@ -243,6 +243,7 @@ PHP_METHOD(yaf_request_http, __construct) {
yaf_request_t *self = getThis();
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ss", &request_uri, &rlen, &base_uri, &blen) == FAILURE) {
+ YAF_UNINITIALIZED_OBJECT(getThis());
return;
}
View
4 requests/simple.c
@@ -14,7 +14,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: simple.c 327283 2012-08-26 07:58:18Z laruence $ */
+/* $Id: simple.c 327549 2012-09-09 03:02:48Z laruence $ */
static zend_class_entry *yaf_request_simple_ce;
@@ -127,9 +127,11 @@ PHP_METHOD(yaf_request_simple, __construct) {
zval *self = getThis();
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|zzzzz", &method, &module, &controller, &action, &params) == FAILURE) {
+ YAF_UNINITIALIZED_OBJECT(getThis());
return;
} else {
if ((params && IS_ARRAY != Z_TYPE_P(params))) {
+ YAF_UNINITIALIZED_OBJECT(getThis());
yaf_trigger_error(YAF_ERR_TYPE_ERROR TSRMLS_CC,
"Expects the params is an array", yaf_request_simple_ce->name);
RETURN_FALSE;
View
3 routes/map.c
@@ -14,7 +14,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: map.c 327548 2012-09-09 02:33:16Z laruence $*/
+/* $Id: map.c 327549 2012-09-09 03:02:48Z laruence $*/
zend_class_entry *yaf_route_map_ce;
@@ -152,6 +152,7 @@ PHP_METHOD(yaf_route_map, __construct) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|bs",
&controller_prefer, &delim, &delim_len) == FAILURE) {
+ YAF_UNINITIALIZED_OBJECT(getThis());
return;
}
View
20 routes/regex.c
@@ -14,7 +14,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: regex.c 327548 2012-09-09 02:33:16Z laruence $ */
+/* $Id: regex.c 327549 2012-09-09 03:02:48Z laruence $ */
zend_class_entry *yaf_route_regex_ce;
@@ -198,26 +198,18 @@ PHP_METHOD(yaf_route_regex, __construct) {
yaf_route_t *self = getThis();
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zaa|a", &match, &route, &map, &verify) == FAILURE) {
- yaf_trigger_error(YAF_ERR_TYPE_ERROR TSRMLS_CC, "Expects an array as third paramter", yaf_route_regex_ce->name);
- WRONG_PARAM_COUNT;
+ YAF_UNINITIALIZED_OBJECT(getThis());
+ return;
}
if (IS_STRING != Z_TYPE_P(match) || !Z_STRLEN_P(match)) {
- yaf_trigger_error(YAF_ERR_TYPE_ERROR TSRMLS_CC, "Expects a string as the first parameter", yaf_route_regex_ce->name);
- RETURN_FALSE;
- }
-
- if (Z_TYPE_P(route) != IS_ARRAY) {
- yaf_trigger_error(YAF_ERR_TYPE_ERROR TSRMLS_CC, "Expects a array as the second parameter", yaf_route_regex_ce->name);
- RETURN_FALSE;
- }
-
- if (IS_ARRAY != Z_TYPE_P(map)) {
- yaf_trigger_error(YAF_ERR_TYPE_ERROR TSRMLS_CC, "Expects an array as third parameter", yaf_route_regex_ce->name);
+ YAF_UNINITIALIZED_OBJECT(getThis());
+ yaf_trigger_error(YAF_ERR_TYPE_ERROR TSRMLS_CC, "Expects a valid string as the first parameter", yaf_route_regex_ce->name);
RETURN_FALSE;
}
if (verify && IS_ARRAY != Z_TYPE_P(verify)) {
+ YAF_UNINITIALIZED_OBJECT(getThis());
yaf_trigger_error(YAF_ERR_TYPE_ERROR TSRMLS_CC, "Expects an array as verify parmater", yaf_route_regex_ce->name);
RETURN_FALSE;
}
View
12 routes/rewrite.c
@@ -14,7 +14,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: rewrite.c 327548 2012-09-09 02:33:16Z laruence $ */
+/* $Id: rewrite.c 327549 2012-09-09 03:02:48Z laruence $ */
zend_class_entry *yaf_route_rewrite_ce;
@@ -259,20 +259,18 @@ PHP_METHOD(yaf_route_rewrite, __construct) {
yaf_route_t *self = getThis();
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "za|a", &match, &route, &verify) == FAILURE) {
+ YAF_UNINITIALIZED_OBJECT(getThis());
return;
}
if (IS_STRING != Z_TYPE_P(match) || !Z_STRLEN_P(match)) {
- yaf_trigger_error(YAF_ERR_TYPE_ERROR TSRMLS_CC, "Expects a string as the first parameter", yaf_route_rewrite_ce->name);
- RETURN_FALSE;
- }
-
- if (IS_ARRAY != Z_TYPE_P(route)) {
- yaf_trigger_error(YAF_ERR_TYPE_ERROR TSRMLS_CC, "Expects an array as the second parameter", yaf_route_rewrite_ce->name);
+ YAF_UNINITIALIZED_OBJECT(getThis());
+ yaf_trigger_error(YAF_ERR_TYPE_ERROR TSRMLS_CC, "Expects a valid string as the first parameter", yaf_route_rewrite_ce->name);
RETURN_FALSE;
}
if (verify && IS_ARRAY != Z_TYPE_P(verify)) {
+ YAF_UNINITIALIZED_OBJECT(getThis());
yaf_trigger_error(YAF_ERR_TYPE_ERROR TSRMLS_CC, "Expects an array as third parameter", yaf_route_rewrite_ce->name);
RETURN_FALSE;
}
View
4 routes/simple.c
@@ -14,7 +14,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: simple.c 327548 2012-09-09 02:33:16Z laruence $ */
+/* $Id: simple.c 327549 2012-09-09 03:02:48Z laruence $ */
zend_class_entry *yaf_route_simple_ce;
@@ -100,12 +100,14 @@ PHP_METHOD(yaf_route_simple, __construct) {
zval *module, *controller, *action;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz", &module, &controller, &action) == FAILURE) {
+ YAF_UNINITIALIZED_OBJECT(getThis());
return;
}
if (IS_STRING != Z_TYPE_P(module)
|| IS_STRING != Z_TYPE_P(controller)
|| IS_STRING != Z_TYPE_P(action)) {
+ YAF_UNINITIALIZED_OBJECT(getThis());
yaf_trigger_error(YAF_ERR_TYPE_ERROR TSRMLS_CC, "Expect 3 string paramsters", yaf_route_simple_ce->name);
RETURN_FALSE;
} else {
View
6 routes/supervar.c
@@ -14,7 +14,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: supervar.c 327548 2012-09-09 02:33:16Z laruence $ */
+/* $Id: supervar.c 327549 2012-09-09 03:02:48Z laruence $ */
#define YAF_ROUTE_SUPERVAR_PROPETY_NAME_VAR "_var_name"
@@ -89,11 +89,13 @@ PHP_METHOD(yaf_route_supervar, __construct) {
zval *var;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &var) == FAILURE) {
+ YAF_UNINITIALIZED_OBJECT(getThis());
return;
}
if (Z_TYPE_P(var) != IS_STRING || !Z_STRLEN_P(var)) {
- yaf_trigger_error(YAF_ERR_TYPE_ERROR TSRMLS_CC, "Expects a string super var name", yaf_route_supervar_ce->name);
+ YAF_UNINITIALIZED_OBJECT(getThis());
+ yaf_trigger_error(YAF_ERR_TYPE_ERROR TSRMLS_CC, "Expects a valid string super var name", yaf_route_supervar_ce->name);
RETURN_FALSE;
}
View
8 tests/051.phpt
@@ -9,16 +9,16 @@ report_memleaks=0
--FILE--
<?php
error_reporting(E_ALL & ~E_WARNING);
-$x = new Yaf_Route_Map("abc://foobar","abc://foobar","abc://foobar","abc://foobar","abc://foobar");
+$x = new Yaf_Route_Map(true);
$x->route($x);
-$x = new Yaf_Route_Static("abc://foobar","abc://foobar","abc://foobar","abc://foobar","abc://foobar");
+$x = new Yaf_Route_Static();
$x->route($x);
-$x = new Yaf_Route_Rewrite("abc://foobar", array(), array(), array(),"abc://foobar");
+$x = new Yaf_Route_Rewrite("#^/test#", array("controller" => "info"), array());
$x->route($x);
-$x = new Yaf_Route_Supervar("abc://foobar","abc://foobar","abc://foobar","abc://foobar","abc://foobar");
+$x = new Yaf_Route_Supervar("r");
$x->route($x);
$x = new Yaf_Route_Regex("#^/test#", array("controller" => "info"), array());
View
3 views/simple.c
@@ -14,7 +14,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: simple.c 327509 2012-09-07 03:26:22Z laruence $ */
+/* $Id: simple.c 327549 2012-09-09 03:02:48Z laruence $ */
#include "main/php_output.h"
@@ -643,6 +643,7 @@ PHP_METHOD(yaf_view_simple, __construct) {
zval *tpl_dir, *options = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|a", &tpl_dir, &options) == FAILURE) {
+ YAF_UNINITIALIZED_OBJECT(getThis());
return;
}
View
8 yaf_application.c
@@ -14,7 +14,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: yaf_application.c 327541 2012-09-08 12:46:24Z laruence $ */
+/* $Id: yaf_application.c 327549 2012-09-09 03:02:48Z laruence $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -336,7 +336,7 @@ PHP_METHOD(yaf_application, __construct) {
self = getThis();
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", &config, &section) == FAILURE) {
- yaf_trigger_error(YAF_ERR_STARTUP_FAILED TSRMLS_CC, "%s::__construct expects at least 1 parameter, 0 give", yaf_application_ce->name);
+ YAF_UNINITIALIZED_OBJECT(getThis());
return;
}
@@ -354,6 +354,7 @@ PHP_METHOD(yaf_application, __construct) {
|| !instanceof_function(Z_OBJCE_P(zconfig), yaf_config_ce TSRMLS_CC)
|| yaf_application_parse_option(zend_read_property(yaf_config_ce,
zconfig, ZEND_STRL(YAF_CONFIG_PROPERT_NAME), 1 TSRMLS_CC) TSRMLS_CC) == FAILURE) {
+ YAF_UNINITIALIZED_OBJECT(getThis());
yaf_trigger_error(YAF_ERR_STARTUP_FAILED TSRMLS_CC, "Initialization of application config failed");
RETURN_FALSE;
}
@@ -365,6 +366,7 @@ PHP_METHOD(yaf_application, __construct) {
}
if (!request) {
+ YAF_UNINITIALIZED_OBJECT(getThis());
yaf_trigger_error(YAF_ERR_STARTUP_FAILED TSRMLS_CC, "Initialization of request failed");
RETURN_FALSE;
}
@@ -373,6 +375,7 @@ PHP_METHOD(yaf_application, __construct) {
if (NULL == zdispatcher
|| Z_TYPE_P(zdispatcher) != IS_OBJECT
|| !instanceof_function(Z_OBJCE_P(zdispatcher), yaf_dispatcher_ce TSRMLS_CC)) {
+ YAF_UNINITIALIZED_OBJECT(getThis());
yaf_trigger_error(YAF_ERR_STARTUP_FAILED TSRMLS_CC, "Instantiation of application dispatcher failed");
RETURN_FALSE;
}
@@ -399,6 +402,7 @@ PHP_METHOD(yaf_application, __construct) {
}
if (!loader) {
+ YAF_UNINITIALIZED_OBJECT(getThis());
yaf_trigger_error(YAF_ERR_STARTUP_FAILED TSRMLS_CC, "Initialization of application auto loader failed");
RETURN_FALSE;
}
View
8 yaf_exception.h
@@ -14,7 +14,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: yaf_exception.h 327283 2012-08-26 07:58:18Z laruence $ */
+/* $Id: yaf_exception.h 327549 2012-09-09 03:02:48Z laruence $ */
#ifndef YAF_EXCEPTION_H
#define YAF_EXCEPTION_H
@@ -61,6 +61,12 @@
EG(current_execute_data)->opline = EG(opline_before_exception); \
} while(0)
+#define YAF_UNINITIALIZED_OBJECT(obj) \
+ do { \
+ zval_dtor(obj); \
+ ZVAL_FALSE(obj); \
+ } while(0)
+
extern zend_class_entry *yaf_ce_RuntimeException;
extern zend_class_entry *yaf_exception_ce;
extern zend_class_entry *yaf_buildin_exceptions[YAF_MAX_BUILDIN_EXCEPTION];

0 comments on commit c1e901a

Please sign in to comment.
Something went wrong with that request. Please try again.