Skip to content

Commit

Permalink
chore(agent): ensure zend_eval_string is called only when class or va…
Browse files Browse the repository at this point in the history
…riable exists
  • Loading branch information
hahuja2 committed Feb 10, 2024
1 parent 4746cca commit c7fd9ef
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 30 deletions.
43 changes: 33 additions & 10 deletions agent/fw_drupal8.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,18 +534,41 @@ NR_PHP_WRAPPER(nr_drupal8_name_the_wt_via_symfony) {
NR_PHP_WRAPPER_END

void nr_drupal_version() {
char* string = "Drupal::VERSION;";
char* func_string
= "if (!function_exists('newrelic_drupal_get_version')) {"
" function newrelic_drupal_get_version() {"
" try {"
" if (class_exists('Drupal')) {"
" return Drupal::VERSION;"
" }"
" else {"
" return ' ';"
" }"
" } catch (Exception $e) {"
" }"
" }"
"}";

zval retval;
int result
= zend_eval_string(string, &retval, "Retrieve Drupal Version");

// Add php package to transaction
if (result == SUCCESS) {
if (Z_TYPE(retval) == IS_STRING) {
char* version = Z_STRVAL(retval);
nr_txn_add_php_package(NRPRG(txn), "drupal/core", version);
int result = zend_eval_string(func_string, NULL,
"Define Drupal Get Version Function");
if (SUCCESS != result) {
return;
}

zend_function* func = nr_php_find_function("newrelic_drupal_get_version");

if (func) {
result = zend_eval_string("newrelic_drupal_get_version();", &retval,
"Get Drupal Version");
// Add php package to transaction
if (SUCCESS == result) {
if (IS_STRING == Z_TYPE(retval)) {
char* version = Z_STRVAL(retval);
nr_txn_add_php_package(NRPRG(txn), "drupal/core", version);
}
zval_dtor(&retval);
}
zval_dtor(&retval);
}
}

Expand Down
43 changes: 33 additions & 10 deletions agent/fw_wordpress.c
Original file line number Diff line number Diff line change
Expand Up @@ -658,18 +658,41 @@ NR_PHP_WRAPPER_END
#endif /* PHP 7.4+ */

void nr_wordpress_version() {
char* string = "$GLOBALS['wp_version'];";
char* func_string
= "if (!function_exists('newrelic_wordpress_get_version')) {"
" function newrelic_wordpress_get_version() {"
" try {"
" if (isset($GLOBALS['wp_version'])) {"
" return $GLOBALS['wp_version'];"
" }"
" else {"
" return ' ';"
" }"
" } catch (Exception $e) {"
" }"
" }"
"}";

zval retval;
int result = zend_eval_string(string, &retval,
"Retrieve Wordpress Version");

// Add php package to transaction
if (result == SUCCESS) {
if (Z_TYPE(retval) == IS_STRING) {
char* version = Z_STRVAL(retval);
nr_txn_add_php_package(NRPRG(txn), "wordpress", version);
int result = zend_eval_string(func_string, NULL,
"Define Wordpress Get Version Function");
if (SUCCESS != result) {
return;
}

zend_function* func = nr_php_find_function("newrelic_wordpress_get_version");

if (func) {
result = zend_eval_string("newrelic_wordpress_get_version();", &retval,
"Get Wordpress Version");
// Add php package to transaction
if (SUCCESS == result) {
if (IS_STRING == Z_TYPE(retval)) {
char* version = Z_STRVAL(retval);
nr_txn_add_php_package(NRPRG(txn), "wordpress", version);
}
zval_dtor(&retval);
}
zval_dtor(&retval);
}
}

Expand Down
47 changes: 37 additions & 10 deletions agent/lib_phpunit.c
Original file line number Diff line number Diff line change
Expand Up @@ -667,18 +667,45 @@ static int nr_phpunit_are_statuses_valid(TSRMLS_D) {
}

void nr_phpunit_version() {
char* string = "PHPUnit\\Runner\\Version::id();";
char* func_string
= ""
"if (!function_exists('newrelic_phpunit_get_version')) {"
" function newrelic_phpunit_get_version() {"
" try {"
" if (class_exists('PHPUnit\\Runner\\Version')) {"
" return PHPUnit\\Runner\\Versions::id();"
" }"
" else if (class_exists('PHPUnit_Runner_Version')) {"
" return PHPUnit_Runner_Versions::id();"
" }"
" else {"
" return ' ';"
" }"
" } catch (Exception $e) {"
" }"
" }"
"}";

zval retval;
int result
= zend_eval_string(string, &retval, "Retrieve PHPUnit Version");

// Add php package to transaction
if (result == SUCCESS) {
if (Z_TYPE(retval) == IS_STRING) {
char* version = Z_STRVAL(retval);
nr_txn_add_php_package(NRPRG(txn), "phpunit/phpunit", version);
int result = zend_eval_string(func_string, NULL,
"Define PHPUnit Get Version Function");
if (SUCCESS != result) {
return;
}

zend_function* func = nr_php_find_function("newrelic_phpunit_get_version");

if (func) {
result = zend_eval_string("newrelic_phpunit_get_version();", &retval,
"Get PHPUnit Version");
// Add php package to transaction
if (SUCCESS == result) {
if (IS_STRING == Z_TYPE(retval)) {
char* version = Z_STRVAL(retval);
nr_txn_add_php_package(NRPRG(txn), "phpunit/phpunit", version);
}
zval_dtor(&retval);
}
zval_dtor(&retval);
}
}

Expand Down

0 comments on commit c7fd9ef

Please sign in to comment.