Skip to content

Commit

Permalink
Fixed bug that alter_response is not binary safe
Browse files Browse the repository at this point in the history
  • Loading branch information
laruence committed Aug 21, 2013
1 parent a836f3a commit 1a64dc2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 16 deletions.
7 changes: 7 additions & 0 deletions package2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@
<file name="060.phpt" role="test" />
<file name="061.phpt" role="test" />
<file name="062.phpt" role="test" />
<file name="063.phpt" role="test" />
<file name="064.phpt" role="test" />
<file name="065.phpt" role="test" />
<file name="066.phpt" role="test" />
<file name="067.phpt" role="test" />
<file name="068.phpt" role="test" />
<file name="069.phpt" role="test" />
<file name="build.inc" role="test" />
<file name="bug61493.phpt" role="test" />
<file name="bug63381.phpt" role="test" />
Expand Down
Binary file added tests/069.phpt
Binary file not shown.
51 changes: 35 additions & 16 deletions yaf_response.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
/* }}} */
Expand Down

0 comments on commit 1a64dc2

Please sign in to comment.