From 0262f05c17d41ed1c9e501c47650564376c9dba1 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Fri, 16 Feb 2007 13:12:10 +0000 Subject: [PATCH] Fixed return value of assert_options(ASSERT_CALLBACK) and possible crash (Andy Wharmby) --- ext/standard/assert.c | 22 ++++++++++++++++------ ext/standard/basic_functions.c | 1 + 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/ext/standard/assert.c b/ext/standard/assert.c index 632a8801068..36f717085a3 100644 --- a/ext/standard/assert.c +++ b/ext/standard/assert.c @@ -114,6 +114,16 @@ PHP_MSHUTDOWN_FUNCTION(assert) return SUCCESS; } +PHP_RINIT_FUNCTION(assert) +{ + if (ASSERTG(cb)) { + MAKE_STD_ZVAL(ASSERTG(callback)); + ZVAL_STRING(ASSERTG(callback), ASSERTG(cb), 1); + } + + return SUCCESS; +} + PHP_RSHUTDOWN_FUNCTION(assert) { if (ASSERTG(callback)) { @@ -187,11 +197,6 @@ PHP_FUNCTION(assert) RETURN_TRUE; } - if (!ASSERTG(callback) && ASSERTG(cb)) { - MAKE_STD_ZVAL(ASSERTG(callback)); - ZVAL_STRING(ASSERTG(callback), ASSERTG(cb), 1); - } - if (ASSERTG(callback)) { zval *args[3]; zval *retval; @@ -286,6 +291,11 @@ PHP_FUNCTION(assert_options) break; case ASSERT_CALLBACK: + if (ASSERTG(callback) != NULL) { + RETVAL_ZVAL(ASSERTG(callback), 1, 0); + } else { + RETVAL_NULL(); + } if (ac == 2) { if (ASSERTG(callback)) { zval_ptr_dtor(&ASSERTG(callback)); @@ -293,7 +303,7 @@ PHP_FUNCTION(assert_options) ASSERTG(callback) = *value; zval_add_ref(value); } - RETURN_TRUE; + return; break; default: diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 0a0009d1332..a79d49a8dcd 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -4132,6 +4132,7 @@ PHP_RINIT_FUNCTION(basic) #ifdef HAVE_SYSLOG_H PHP_RINIT(syslog)(INIT_FUNC_ARGS_PASSTHRU); #endif + PHP_RINIT(assert) (INIT_FUNC_ARGS_PASSTHRU); PHP_RINIT(dir)(INIT_FUNC_ARGS_PASSTHRU); PHP_RINIT(url_scanner_ex)(INIT_FUNC_ARGS_PASSTHRU);