Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 8 curl Object Fixes #70

Merged
merged 7 commits into from
Dec 22, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions agent/php_curl.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ static int nr_php_curl_do_cross_process(TSRMLS_D) {
|| NRPRG(txn)->options.distributed_tracing_enabled);
}

static int nr_php_is_zval_valid_curl_handle(const zval* ch) {
#if ZEND_MODULE_API_NO >= ZEND_8_0_X_API_NO /* PHP 8.0+ */
return NULL != ch && nr_php_is_zval_valid_object(ch);
#else
return NULL != ch && nr_php_is_zval_valid_resource(ch);
#endif /* PHP 8.0+ */
}

static void nr_php_curl_save_response_header_from_zval(const zval* ch,
const zval* zstr
TSRMLS_DC) {
Expand Down Expand Up @@ -113,7 +121,7 @@ static void nr_php_curl_set_default_response_header_callback(
zval* retval = NULL;
zval* curlopt = NULL;

if ((NULL == curlres) || (IS_RESOURCE != Z_TYPE_P(curlres))) {
if ((NULL == curlres)) {
return;
}

Expand All @@ -137,7 +145,7 @@ static void nr_php_curl_set_default_request_headers(zval* curlres TSRMLS_DC) {
zval* retval = NULL;
zval* curlopt = NULL;

if ((NULL == curlres) || (IS_RESOURCE != Z_TYPE_P(curlres))) {
if (!nr_php_is_zval_valid_curl_handle(curlres)) {
return;
}

Expand Down Expand Up @@ -421,8 +429,8 @@ void nr_php_curl_setopt_pre(zval* curlres,
return;
}

if ((NULL == curlres) || (NULL == curlopt) || (NULL == curlval)
|| (IS_RESOURCE != Z_TYPE_P(curlres)) || (IS_LONG != Z_TYPE_P(curlopt))) {
if (!nr_php_is_zval_valid_curl_handle(curlres) || (NULL == curlopt)
|| (NULL == curlval) || (IS_LONG != Z_TYPE_P(curlopt))) {
return;
}

Expand All @@ -445,8 +453,8 @@ void nr_php_curl_setopt_post(zval* curlres,
return;
}

if ((NULL == curlres) || (NULL == curlopt) || (NULL == curlval)
|| (IS_RESOURCE != Z_TYPE_P(curlres)) || (IS_LONG != Z_TYPE_P(curlopt))) {
if (!nr_php_is_zval_valid_curl_handle(curlres) || (NULL == curlopt)
|| (NULL == curlval) || (IS_LONG != Z_TYPE_P(curlopt))) {
return;
}

Expand Down Expand Up @@ -526,7 +534,7 @@ void nr_php_curl_setopt_array(zval* curlres,
.func = func,
};

if (!nr_php_is_zval_valid_resource(curlres)
if (!nr_php_is_zval_valid_curl_handle(curlres)
|| !nr_php_is_zval_valid_array(options)) {
return;
}
Expand All @@ -541,7 +549,7 @@ static bool nr_php_curl_finished(zval* curlres TSRMLS_DC) {
zval* result = NULL;
bool finished = false;

if (!nr_php_is_zval_valid_resource(curlres)) {
if (!nr_php_is_zval_valid_curl_handle(curlres)) {
return false;
}

Expand Down
15 changes: 15 additions & 0 deletions agent/php_curl_md.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ static void nr_php_curl_md_destroy(nr_php_curl_md_t* metadata) {
nr_free(metadata);
}

#if ZEND_MODULE_API_NO >= ZEND_8_0_X_API_NO /* PHP 8.0+ */
#define check_curl_handle(ch) \
({ \
bool __ok = true; \
\
if (nrunlikely(!nr_php_is_zval_valid_object(ch))) { \
nrl_verbosedebug(NRL_CAT, "%s: invalid curl handle; not an object", \
__func__); \
__ok = false; \
} \
\
__ok; \
})
#else
#define check_curl_handle(ch) \
({ \
bool __ok = true; \
Expand All @@ -26,6 +40,7 @@ static void nr_php_curl_md_destroy(nr_php_curl_md_t* metadata) {
\
__ok; \
})
#endif

#define ensure_curl_metadata_hashmap() \
if (!NRTXNGLOBAL(curl_metadata)) { \
Expand Down
23 changes: 20 additions & 3 deletions agent/php_internal_instrument.c
Original file line number Diff line number Diff line change
Expand Up @@ -2189,9 +2189,14 @@ NR_INNER_WRAPPER(curl_exec) {
zval* curlres = NULL;
int zcaught = 0;

if (SUCCESS
!= zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET,
ZEND_NUM_ARGS() TSRMLS_CC, "r", &curlres)) {
#if ZEND_MODULE_API_NO >= ZEND_8_0_X_API_NO /* PHP 8.0+ */
int parse_status = zend_parse_parameters_ex(
ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "o", &curlres);
#else
int parse_status = zend_parse_parameters_ex(
ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "r", &curlres);
#endif /* PHP 8.0+ */
if (SUCCESS != parse_status) {
nr_wrapper->oldhandler(INTERNAL_FUNCTION_PARAM_PASSTHRU);
return;
}
Expand Down Expand Up @@ -2221,9 +2226,15 @@ NR_INNER_WRAPPER(curl_multi_add_handle) {
zval* curlres = NULL;
int rv = FAILURE;

#if ZEND_MODULE_API_NO >= ZEND_8_0_X_API_NO /* PHP 8.0+ */
rv = zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET,
ZEND_NUM_ARGS() TSRMLS_CC, "oo", &multires,
&curlres);
#else
rv = zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET,
ZEND_NUM_ARGS() TSRMLS_CC, "rr", &multires,
&curlres);
#endif /* PHP 8.0+ */

if (SUCCESS == rv) {
if (nr_php_curl_multi_md_add(multires, curlres TSRMLS_CC)
Expand Down Expand Up @@ -2255,9 +2266,15 @@ NR_INNER_WRAPPER(curl_multi_remove_handle) {
zval* curlres = NULL;
int rv = FAILURE;

#if ZEND_MODULE_API_NO >= ZEND_8_0_X_API_NO /* PHP 8.0+ */
rv = zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET,
ZEND_NUM_ARGS() TSRMLS_CC, "oo", &multires,
&curlres);
#else
rv = zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET,
ZEND_NUM_ARGS() TSRMLS_CC, "rr", &multires,
&curlres);
#endif /* PHP 8.0+ */

if (SUCCESS == rv) {
if (nr_php_curl_multi_md_remove(multires, curlres TSRMLS_CC)) {
Expand Down