Skip to content

Commit

Permalink
PCBC-476: Do not call destructors on uninitialized values
Browse files Browse the repository at this point in the history
Change-Id: I68510f9c3cad82fa887936e532640e03fb7e0f78
Reviewed-on: http://review.couchbase.org/76581
Tested-by: Build Bot <[email protected]>
Reviewed-by: Sergey Avseyev <[email protected]>
  • Loading branch information
avsej committed Apr 12, 2017
1 parent 432c2e5 commit 7ced000
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 24 deletions.
2 changes: 2 additions & 0 deletions package2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
* PCBC-473: fix incorrect bucket reference copy in subdocument
mutation/lookup builders, which might lead to segfault.
* PCBC-474: fix segfault when using ViewQuery::keys()
* PCBC-476: do not call destructors on unintialized ZVALs. Fixes possible
segfaults with view queries on PHP 5.x.
</notes>

<contents>
Expand Down
4 changes: 1 addition & 3 deletions src/couchbase/bucket/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ void http_callback(lcb_t instance, int cbtype, const lcb_RESPBASE *rb)
pcbc_log(LOGARGS(instance, WARN), "Failed to perform HTTP request: rc=%d", (int)resp->rc);
}

#if PHP_VERSION_ID < 70000
MAKE_STD_ZVAL(result->bytes);
#endif
PCBC_ZVAL_ALLOC(result->bytes);
if (resp->nbody) {
if (((opcookie *)rb->cookie)->json_response) {
int last_error;
Expand Down
10 changes: 4 additions & 6 deletions src/couchbase/bucket/n1ql.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ static void n1qlrow_callback(lcb_t instance, int ignoreme, const lcb_RESPN1QL *r
result->header.err = LCB_SUCCESS;
}
result->rflags = resp->rflags;
#if PHP_VERSION_ID < 70000
MAKE_STD_ZVAL(result->row);
#endif
PCBC_ZVAL_ALLOC(result->row);
ZVAL_NULL(PCBC_P(result->row));
if (cookie->json_response) {
int last_error;
int json_options = cookie->json_options;
Expand Down Expand Up @@ -104,9 +103,8 @@ static lcb_error_t proc_n1qlrow_results(zval *return_value, opcookie *cookie TSR

if (err == LCB_SUCCESS) {
PCBC_ZVAL rows;
#if PHP_VERSION_ID < 70000
MAKE_STD_ZVAL(rows);
#endif

PCBC_ZVAL_ALLOC(rows);
array_init(PCBC_P(rows));

object_init(return_value);
Expand Down
27 changes: 12 additions & 15 deletions src/couchbase/bucket/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ static void viewrow_callback(lcb_t instance, int ignoreme, const lcb_RESPVIEWQUE
int last_error;
TSRMLS_FETCH();

#if PHP_VERSION_ID < 70000
MAKE_STD_ZVAL(result->id);
MAKE_STD_ZVAL(result->key);
MAKE_STD_ZVAL(result->value);
#endif
PCBC_ZVAL_ALLOC(result->id);
PCBC_ZVAL_ALLOC(result->key);
PCBC_ZVAL_ALLOC(result->value);

ZVAL_NULL(PCBC_P(result->id));
ZVAL_NULL(PCBC_P(result->key));
ZVAL_NULL(PCBC_P(result->value));

result->header.err = resp->rc;
result->rflags = resp->rflags;
if (result->header.err == LCB_SUCCESS) {
Expand All @@ -57,8 +60,6 @@ static void viewrow_callback(lcb_t instance, int ignoreme, const lcb_RESPVIEWQUE
last_error);
PCBC_STRINGL(result->value, resp->value, resp->nvalue);
}
} else {
ZVAL_NULL(PCBC_P(result->value));
}

if (resp->nkey) {
Expand All @@ -70,8 +71,6 @@ static void viewrow_callback(lcb_t instance, int ignoreme, const lcb_RESPVIEWQUE
PCBC_STRINGL(result->key, resp->key, resp->nkey);
}
}
} else {
ZVAL_NULL(PCBC_P(result->key));
}
} else {
PCBC_STRINGL(result->key, resp->key, resp->nkey);
Expand Down Expand Up @@ -132,9 +131,8 @@ static lcb_error_t proc_viewrow_results(zval *return_value, opcookie *cookie TSR

if (err == LCB_SUCCESS) {
PCBC_ZVAL rows;
#if PHP_VERSION_ID < 70000
MAKE_STD_ZVAL(rows);
#endif

PCBC_ZVAL_ALLOC(rows);
array_init(PCBC_P(rows));

object_init(return_value);
Expand All @@ -153,9 +151,8 @@ static lcb_error_t proc_viewrow_results(zval *return_value, opcookie *cookie TSR
}
} else {
PCBC_ZVAL row;
#if PHP_VERSION_ID < 70000
MAKE_STD_ZVAL(row);
#endif

PCBC_ZVAL_ALLOC(row);
object_init(PCBC_P(row));
add_property_zval(PCBC_P(row), "id", PCBC_P(res->id));
add_property_zval(PCBC_P(row), "key", PCBC_P(res->key));
Expand Down

0 comments on commit 7ced000

Please sign in to comment.