Skip to content

Commit

Permalink
Do not indirectly modify properties with refcount > 1
Browse files Browse the repository at this point in the history
  • Loading branch information
sjinks committed Oct 3, 2013
1 parent 3d03848 commit 71ba11a
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions ext/logger/adapter/firephp.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "kernel/memory.h"
#include "kernel/fcall.h"
#include "kernel/object.h"
#include "kernel/operators.h"
#include "kernel/exception.h"

#include "logger/adapter/firephp.h"
Expand Down Expand Up @@ -107,6 +108,7 @@ PHP_METHOD(Phalcon_Logger_Adapter_Firephp, logInternal){
smart_str str = { NULL, 0, 0 };
int size, offset, num_bytes;
const int chunk = 4960;
int separated_index = 0;

/* If headers has already been sent, we can do nothing. Exit early. */
if (SG(headers_sent)) {
Expand All @@ -120,8 +122,8 @@ PHP_METHOD(Phalcon_Logger_Adapter_Firephp, logInternal){
PHALCON_INIT_VAR(formatter);
phalcon_call_method(formatter, this_ptr, "getformatter");

PHALCON_OBS_VAR(initialized);
phalcon_read_static_property(&initialized, SL("phalcon\\logger\\adapter\\firephp"), SL("_initialized") TSRMLS_CC);
Z_DELREF_P(initialized);
if (!zend_is_true(initialized)) {
/**
* Send the required initialization headers.
Expand All @@ -141,7 +143,16 @@ PHP_METHOD(Phalcon_Logger_Adapter_Firephp, logInternal){
h.line_len = sizeof("X-Wf-1-Structure-1: http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1")-1;
sapi_header_op(SAPI_HEADER_REPLACE, &h TSRMLS_CC);

ZVAL_TRUE(initialized); /* This will also update the property because "initialized" was not separated */
if (Z_REFCOUNT_P(initialized) == 1) {
zval_dtor(initialized);
ZVAL_TRUE(initialized); /* This will also update the property because "initialized" was not separated */
}
else {
MAKE_STD_ZVAL(initialized);
ZVAL_TRUE(initialized);
Z_DELREF_P(initialized);
phalcon_update_static_property_nts(phalcon_logger_adapter_firephp_ce, SL("_initialized"), initialized TSRMLS_CC);
}
}

PHALCON_INIT_VAR(applied_format);
Expand All @@ -151,8 +162,15 @@ PHP_METHOD(Phalcon_Logger_Adapter_Firephp, logInternal){
return;
}

PHALCON_OBS_VAR(index);
phalcon_read_static_property(&index, SL("phalcon\\logger\\adapter\\firephp"), SL("_index") TSRMLS_CC);
Z_DELREF_P(index);

if (Z_REFCOUNT_P(index) > 1) {
long int idx = phalcon_get_intval(index);
PHALCON_INIT_VAR(index);
ZVAL_LONG(index, idx);
separated_index = 1;
}

size = Z_STRLEN_P(applied_format);
offset = 0;
Expand Down Expand Up @@ -202,6 +220,10 @@ PHP_METHOD(Phalcon_Logger_Adapter_Firephp, logInternal){
str.len = 0;
}

if (separated_index) {
phalcon_update_static_property_nts(phalcon_logger_adapter_firephp_ce, SL("_index"), index TSRMLS_CC);
}

/* Deallocate the smnart string if it is not empty */
if (str.c) {
smart_str_free(&str);
Expand Down

0 comments on commit 71ba11a

Please sign in to comment.