diff --git a/package2.xml b/package2.xml index 3d370eda..90ecb541 100644 --- a/package2.xml +++ b/package2.xml @@ -156,6 +156,13 @@ + + + + + + + diff --git a/tests/069.phpt b/tests/069.phpt new file mode 100644 index 00000000..cecc1b65 Binary files /dev/null and b/tests/069.phpt differ diff --git a/yaf_response.c b/yaf_response.c index 8cfe9b11..a9471df9 100644 --- a/yaf_response.c +++ b/yaf_response.c @@ -130,6 +130,7 @@ static int yaf_response_set_body(yaf_response_t *response, char *name, int name_ int yaf_response_alter_body(yaf_response_t *response, char *name, int name_len, char *body, long body_len, int flag TSRMLS_DC) { zval *zbody, **ppzval; char *obody; + long obody_len; if (!body_len) { return 1; @@ -144,28 +145,46 @@ int yaf_response_alter_body(yaf_response_t *response, char *name, int name_len, if (zend_hash_find(Z_ARRVAL_P(zbody), name, name_len + 1, (void **)&ppzval) == FAILURE) { zval *body; + obody = NULL; MAKE_STD_ZVAL(body); - ZVAL_EMPTY_STRING(body); + ZVAL_NULL(body); zend_hash_update(Z_ARRVAL_P(zbody), name, name_len +1, (void **)&body, sizeof(zval *), (void **)&ppzval); + } else { + obody = Z_STRVAL_PP(ppzval); + obody_len = Z_STRLEN_PP(ppzval); } - obody = Z_STRVAL_PP(ppzval); - - switch (flag) { - case YAF_RESPONSE_PREPEND: - Z_STRLEN_PP(ppzval) = spprintf(&Z_STRVAL_PP(ppzval), 0, "%s%s", body, obody); - break; - case YAF_RESPONSE_APPEND: - Z_STRLEN_PP(ppzval) = spprintf(&Z_STRVAL_PP(ppzval), 0, "%s%s", obody, body); - break; - case YAF_RESPONSE_REPLACE: - default: - ZVAL_STRINGL(*ppzval, body, body_len, 1); - break; + if (obody) { + char *result; + long result_len; + + switch (flag) { + case YAF_RESPONSE_PREPEND: + result_len = body_len + obody_len; + result = emalloc(result_len + 1); + memcpy(result, body, body_len); + memcpy(result + body_len, obody, obody_len); + result[result_len] = '\0'; + ZVAL_STRINGL(*ppzval, result, result_len, 0); + break; + case YAF_RESPONSE_APPEND: + result_len = body_len + obody_len; + result = emalloc(result_len + 1); + memcpy(result, obody, obody_len); + memcpy(result + obody_len, body, body_len); + result[result_len] = '\0'; + ZVAL_STRINGL(*ppzval, result, result_len, 0); + break; + case YAF_RESPONSE_REPLACE: + default: + ZVAL_STRINGL(*ppzval, body, body_len, 1); + break; + } + efree(obody); + } else { + ZVAL_STRINGL(*ppzval, body, body_len, 1); } - efree(obody); - return 1; } /* }}} */